Skip to content

Commit f6ec5d8

Browse files
author
cpppy
authored
Update and rename 303_Range_Sum_Query_Immutable.cc to 28_Implement_strStr().cc
1 parent 04527c8 commit f6ec5d8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

28_Implement_strStr().cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int strStr(string haystack, string needle) {
4+
if(needle.size()==0) return 0;
5+
if(needle.size()>haystack.size()) return -1;
6+
for(int i=0;i<(haystack.size()-needle.size()+1);++i){
7+
if(haystack[i]==needle[0]){
8+
int j=0;
9+
while(j<needle.size() && haystack[i+j]==needle[j]){
10+
j++;
11+
}
12+
if(j==needle.size()) return i;
13+
}
14+
}
15+
return -1;
16+
}
17+
};

0 commit comments

Comments
 (0)