public class StrStr { // è¿éé常éè¦çæ¯i<=len1-len2ï¼å¦ææ²¡æè¿ä¸ªä¼è¶ æ¶ // æ¯å¦needleé常é¿çæ¶å public int strStr(String haystack, String needle) { int l1 = haystack.length(), l2 = needle.length(); for (int i = 0, j; i + l2 - 1 < l1; i++) { for (j = 0; j < l2; j++) { if (haystack.charAt(i + j) != needle.charAt(j)) { break; } } if (j >= l2) { return i; } } return -1; } }