Open Ni-Guvara opened 1 year ago
class Solution {
public int strStr(String haystack, String needle) {
char[] hc = haystack.toCharArray();
char[] nc = needle.toCharArray();
int i = 0, j = 0;
while(i < hc.length){
if(hc[i] == nc[j]){
i++; j++;
}else{
i = i - j + 1;
j = 0;
}
if(j == nc.length){
return i - j;
}
}
return -1;
}
}