P**********c 发帖数: 3417 | 1 是用suffix tree还是针对这个题目有更简单直观的解法? | w******a 发帖数: 236 | 2 Here is my code. Tested on my dev box:
const char * my_strstr(const char * s1, const char * s2)
{
int i;
for (;s1;s1++) {
for(i=0;s1&s;s1++,s2++,i++) {
if (*s1 != *s2) {
s1 -= i;
s2 -= i;
break;
}
else if (!(*(s2+1))) {
return s1-i;
}
}
}
return 0;
} | f*******t 发帖数: 7549 | | p*****u 发帖数: 310 | 4 Did not check if point is null.
【在 w******a 的大作中提到】 : Here is my code. Tested on my dev box: : const char * my_strstr(const char * s1, const char * s2) : { : int i; : for (;s1;s1++) { : for(i=0;s1&s;s1++,s2++,i++) { : if (*s1 != *s2) { : s1 -= i; : s2 -= i; : break;
| k*j 发帖数: 153 | 5 2 solutions
1.brute force, complexity O(m*n), m is the length of the pattern, n is the
length of the string
2. KMP O(m+n) | s*****y 发帖数: 897 | 6 Should we write the kmp during the interview? Or just write the brute force? |
|