下载此文档

IT算法类面试题.docx


文档分类:IT计算机 | 页数:约14页 举报非法文档有奖
1/14
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/14 下载此文档
文档列表 文档介绍
IT算法类面试题.docx最长回文字串 Longest Palindromic Substring
将字符串S反转得到V,求二者的最长公共子字符串;注意:求最长公共子字符串的过 程中要判断求得的公共串是否是回文,女0 S = "abacd馆dcabaj S' = 想出来。
采用后缀树也是可以的。
判断整数是否是回文 Determine whether an integer is a palindrome without extra space. 1・首先要考虑负数是否属于回文,这里假设不属于;
几种解法:一是将整数转化为字符形式,但需要额外空间;二是将数字逆转 得到另一个数,判断是否与原数相等,但有可能溢出;
乞…程迨娶衣旳方迭是丛数旳函遍回史回推进判軌…如担簣処弃搏苴星数壬
bool isPalindrome(int x) {
if (x < 0) retUTn false;
int div = 1; while (x / div >= 10) { div *二10; } //算数的量级
wh订e (x != 0) { //也可以用递归代替循环 int 1 二 x / div; //取首数字 int r = x % 10; //取尾数字 if (1 != r) retUTn false;
x = (x % div) / 10; //去除首尾 div /= 100;
}
retUTn true;
Implement regular expression matching with support for "・,and "*, ? Matches any single character.
Matches zero or more of the precedi ng element. 怎样 match *?
可以通过查找字符串中重复字符的个数,然后比较个数; 怎样 match".*"?
If the next character of p is NOT then it must match the current character
of s. Continue pattern matching with the next character of both s and p.
If the next character of p is then we do a brute force exhaustive matching
of 0, 1, or more repeats of current character of p.・・ Until we could not match any more characters.
bool isMatch(const char *s, const char *p) {
assert(s && p);
if (*p ==、0') return *s == '\0‘;
// next char is not must match current character
if (*(p+l) !='*') {
assert(*p !=
return ((*p == *s) II (*p == 7 && *s != '\0!)) && isMatch(s+l, p+1);
}
// next char is
while ((*p == *s) II (*p == 7 && *s != '\0!)) {
if (isMatch(s, p+2)) return true;
s++;
}
return isMatch(s, p+2);
}
Insert into a Cyclic Sorted
本体关键是考虑周全,找出所有caseo
Casel: the list is passed in as NULL
Then handle this special case by creating a new node pointing back to itself and return. Case2: prev^val W x W current^val:
Insert between prev and current.
Case3: x is the maximum or minimum value in the list:
Insert before the head, (ie, the head has the smallest value and its prev—val > head—val.
Case4: Traverses back to the starting point:
Insert befo

IT算法类面试题 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数14
  • 收藏数0 收藏
  • 顶次数0
  • 上传人小雄
  • 文件大小106 KB
  • 时间2022-02-22