首页 > 其他 > 详细

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

时间:2019-02-01 17:54:03      阅读:152      评论:0      收藏:0      [点我收藏+]

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

 

 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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!