Implement strStr()
Input: haystack = "hello", needle = "ll"
Output: 2Input: haystack = "aaaaa", needle = "bba"
Output: -1class Solution {
public int strStr(String haystack, String needle) {
if(needle == null || needle.length() == 0) return 0;
for(int i = 0; i <= haystack.length()-needle.length();i++){
if(haystack.substring(i,i+needle.length()).equals(needle)) return i;
}
return -1;
}
}Last updated