Commit a2e11c1d authored by yaozc's avatar yaozc
Browse files

28 solved

parent 9af8a9de
......@@ -71,3 +71,20 @@ int removeElement(vector<int>& nums, int val) {
}
return nums.size()-counter;
}
//28 implement strStr()
int strStr(string haystack, string needle) {
int needle_size = needle.size();
int haystack_size = haystack.size();
if(needle_size == 0){
return 0;
}
for(int i=0; i<haystack_size - needle_size+1; i++){
if(haystack.substr(i,needle_size) == needle){
return i;
}
}
return -1;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment