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
时间: 2024-10-09 20:08:44