码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode 28 Implement Strstr()

时间:2019-05-27 13:19:38      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:class   for   tac   str   etc   leetcode   nbsp   stack   break   

两个for

外层for负责处理原字符串

内层for负责处理匹配字符串

 1 class Solution {
 2     public int strStr(String haystack, String needle) {
 3         for(int i=0;; i++){
 4             for(int j=0;; j++){
 5                 if(j == needle.length())
 6                     return i;
 7                 if(i + j == haystack.length())
 8                     return -1;
 9                 if(haystack.charAt(i+j) != needle.charAt(j))
10                     break;
11             }
12         }
13     }
14 }

 

leetcode 28 Implement Strstr()

标签:class   for   tac   str   etc   leetcode   nbsp   stack   break   

原文地址:https://www.cnblogs.com/hwd9654/p/10930101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!