51,411
社区成员
发帖
与我相关
我的任务
分享class Solution {
public int strStr(String haystack, String needle) {
int i=0,j;
if(needle.length()==0){
return 0;
}
int t = haystack.length()-needle.length();
while(i <= t){
if(needle.equals(haystack.substring(i,i+needle.length())))
return i;
i++;
}
return -1;
}
}
class Solution {
public int strStr(String haystack, String needle) {
int i=0,j;
if(needle.length()==0){
return 0;
}
int t = haystack.length()-needle.length();
while(i <= t){
for(j=0;j<=needle.length();j++){
if(j==needle.length())
return i;
if(haystack.charAt(i+j)!=needle.charAt(j)){
i++;
break;
}
}
}
return -1;
}
}