28. Implement strStr()

来源:互联网 发布:js获取a标签href 编辑:程序博客网 时间:2024/06/06 03:00
int strStr(string haystack, string needle) {    int sz = haystack.size() - needle.size();    for (int i = 0; i <= sz;i++){        int j = 0;        while (j < needle.size() && (haystack[i + j] == needle[j])) {            j++;        }        if (j == needle.size()) return i;    }    return -1;}

0 0
原创粉丝点击