标签:art java etc i++ div while ons imp detail
https://leetcode.com/submissions/detail/108134096/
brute force
public int strStr(String haystack, String needle) {
if (haystack.length() < needle.length()) {
return -1;
}
int start = 0;
while (start <= haystack.length() - needle.length()) {
int i = start, j = 0;
while (j < needle.length() && haystack.charAt(i) == needle.charAt(j)) { // 判断
i++;
j++;
}
if (j == needle.length()) {
return start;
}
start++;
}
return -1;
}
标签:art java etc i++ div while ons imp detail
原文地址:http://www.cnblogs.com/apanda009/p/7109771.html