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

 

 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 }

 

相关文章:

  • 2021-12-01
  • 2021-06-26
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
猜你喜欢
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-15
  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案