您的位置:首页 > 其它

leetcode--28. Implement strStr()

2017-01-15 22:35 363 查看
Implement strStr().

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

题解

class Solution {
public:
int strStr(string haystack, string needle) {
for(int i = 0; ; ++i){
for(int j = 0; ; ++j){
if(j == needle.length()) return i;
if(i + j == haystack.length()) return -1;
if(needle[j] != haystack[i + j]) break;
}
}
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode string