class Solution {
public:
int strStr(string haystack, string needle) {
if (!needle.size())return 0;
for (int i = 0; i < haystack.size(); ++i) {
bool flag = false;
if (haystack[i] == needle[0]) {
for (int j = 0; j < needle.size(); ++j) {
if (haystack[i + j] != needle[j]) {
flag = true;
break;
}
}
if (!flag)return i;
}
}
return -1;
}
};
28 Implement strStr()
猜你喜欢
转载自blog.csdn.net/Leslie5205912/article/details/84437268
今日推荐
周排行