Implement strStr().
Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
c++:class Solution {
public:
char *strStr(char *haystack, char *needle) {
int lenh = strlen(haystack);
int lenn = strlen(needle);
int i,j;
for(i = 0;i <= lenh-lenn;i ++) {
char *p = haystack + i;
for(j = 0;j < lenn;j ++) {
if(*(p + j) != *(needle + j)) {
break;
}
}
if(j == lenn) {
return haystack+i;
}
}
return NULL;
}
};