Skip to content

Commit 036c275

Browse files
authored
Merge pull request gzc426#30 from love15less/master
mcx rquest
2 parents eb9282d + 6e377fd commit 036c275

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

2019.11.15/暮成雪.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
~~~
2+
class Solution {
3+
public int strStr(String haystack, String needle) {
4+
int index=0;
5+
if(needle.length() == 0){
6+
return 0;
7+
}
8+
9+
for(int i=0; i<haystack.length(); i++){
10+
11+
if( needle.length() > (haystack.length()-i) ){
12+
return -1;
13+
}
14+
15+
for(int j=0; j <needle.length(); j++){
16+
if(haystack.charAt(i+j) != needle.charAt(j) ){
17+
break;
18+
}
19+
20+
if(j==needle.length()-1 ){
21+
return i;
22+
}
23+
}
24+
}
25+
return -1;
26+
}
27+
28+
}
29+
~~~

0 commit comments

Comments
 (0)