Leetcode028. Implement strStr()
Posted zeroArn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode028. Implement strStr()相关的知识,希望对你有一定的参考价值。
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()的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode OJ 225Implement Stack using Queues
LeetCode - 28. Implement strStr()
LeetCode Implement Queue using Stacks