题目
解题思路:这次解题思路叫不会就转行,不解释了,哈哈
代码
class Solution {
public int strStr(String haystack, String needle) {
if(haystack==null){
return -1;
}
if(needle==null){
return 0;
}
return haystack.indexOf(needle);
}
}
适当调用函数也是一种能力哦~
hh
不想调用函数那就自己来实现吧~
也是so easy啊
class Solution {
public int strStr(String haystack, String needle) {
if(haystack==null){
return -1;
}
if(needle==null){
return 0;
}
for(int i=0; i<haystack.length()-needle.length()+1;i++){
if(haystack.substring(i,i+needle.length()).equals(needle)){
return i;
}
}
return -1;
}
}
不懂就问