在一个字符串中寻找某个字串

在一个字符串中寻找某个字串

 1 public int strStr(String haystack, String needle) {
 2     for(int i = 0; ; i++) {
 3         for(int j = 0; ; j++) {
 4             if(j == needle.length()) {
 5                 return i;
 6             }
 7 
 8             if(i+j == haystack.length()) {
 9                 return -1;
10             }
11 
12             if(needle.charAt(j) != haystack.charAt(i+j) {
13                 break;
14             }
15         }
16     }
17 }
原文地址:https://www.cnblogs.com/wylwyl/p/10346463.html