标签:
class Solution { public: int strStr(string haystack, string needle) { if(needle.empty())return 0; //needle empty if(haystack.empty()) return -1; //haystack empty for(int i = 0, j = 0; i+j < haystack.size();) { if(haystack[i+j] != needle[j])i++, j = 0; //no equal needle index to 0, haystack index move to next. else j++; //equal both move to next if(j == needle.size())return i; //thr first time find substr. } return -1; } };
Leetcode028. Implement strStr()
标签:
原文地址:http://www.cnblogs.com/zeroArn/p/5877907.html