https://www.lintcode.com/problem/13/?_from=cat
[]
is code correct?
[code]
public class Solution {
/**
* @param source:
* @param target:
* @return: return the index
*/
public int strStr(String source, String target) {
// Write your code here
if(source==null || target==null){
return -1;
}
else if(target.length()==0){
return 0;
}
else if(source.length()==0){
return -1;
}
int m = source.length();
for(int i=0;i<m;i++){
if(match(source, target, i)){
return i;
}
}
return -1;
}
boolean match(String s, String t, int i){
for(int j=0;j<t.length();j++){
if(s.charAt(i+j)!=t.charAt(j)){
return false;
}
}
return true;
}
}