class Solution {
public int strStr(String haystack, String needle) {
int len1 = haystack.length();
int len2 = needle.length();
int i, j;
for (i = 0; i <= (len1 - len2); i++) {
for (j = 0; j < len2; j++) {
if (haystack.charAt(i + j) != needle.charAt(j)) {
break;
}
}
if (len2 == j) {
return i;
}
}
return -1;
}
}
力扣-1.12-28
猜你喜欢
转载自blog.csdn.net/Desperate_gh/article/details/112506820
今日推荐
周排行