leetcode 28. Implement strStr()

来源:互联网 发布:做家装效果图的软件 编辑:程序博客网 时间:2024/06/05 03:47
class Solution {public:int strStr(string haystack, string needle){int res = -1;int j = 0;if (haystack == needle || needle == ""){return 0;}if (haystack.size() < needle.size()){return -1;}for (int i = 0; i < haystack.size() - needle.size(); i++){if (haystack[i] == needle[0]){if (equal(haystack.begin() + i, haystack.begin() + i + needle.size(), needle.begin())){return i;}}}return -1;}};

0 0
原创粉丝点击