class Solution {
public int strStr(String haystack, String needle) {
if(haystack==null){
return -1;
}
if(needle==null){
return 0;
}
int lenn=needle.length();
int lenh=haystack.length();
int i=0;
while (i<=(lenh-lenn)){
String tem=haystack.substring(i,i+lenn);
if(tem.equals(needle)){
return i;
}
i++;
}
return -1;
}
}
实现 strStr() 函数。
最新推荐文章于 2025-01-26 17:36:40 发布