class Solution {
public:
int strStr(string haystack, string needle) {
if (true == needle.empty()) {
return 0;
}
if (true == haystack.empty()) {
return -1;
}
int size0 = haystack.size();
int size1 = needle.size();
int i = 0;
int j = 0;
int k = 0;
while (i < size0) {
k = i;
while (j < size1 && haystack[k] == needle[j]) {
k++;
j++;
continue;
}
if (j == size1) {
return i;
}
i++;
j = 0;
}
return -1;
}
};
leetcode strstr实现
最新推荐文章于 2021-07-26 13:54:19 发布