strstr的非KMP实现方法

来源:互联网 发布:windows loader v3.27 编辑:程序博客网 时间:2024/05/02 04:55
class Solution {public:    char *strStr(char *haystack, char *needle) {        // Start typing your C/C++ solution below        // DO NOT write int main() function        int hayLen = strlen(haystack);        int needLen = strlen(needle);                for(int i = 0; i <= hayLen - needLen; i++)        {            char *p = haystack + i;            char *q = needle;            while(*q != '\0')            {                if (*p != *q)                    break;                else                {                    p++;                    q++;                }            }                        if (*q == '\0')                return haystack + i;                    }                return NULL;    }};

0 0