您的位置:首页 > 其它

LeetCode 28. Implement strStr()

2016-11-17 12:46 369 查看

描述

实现strStr()函数

解决

遍历

class Solution {
public:
int strStr(string haystack, string needle) {
int length2 = needle.size();
int length1 = haystack.size();
if (length1 == 0 && length2 == 0)
return 0;
for (int i = 0; i + length2 - 1< length1; ++i)
{
if (haystack.substr(i, length2) == needle)
return i;
}

return -1;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode