LeetCode – Implement strStr() (Java)

Problem: Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Java Solution 1 – Naive public int strStr(String haystack, String needle) { if(haystack==null || needle==null) return 0;   if(needle.length() == 0) return 0;   for(int i=0; i<haystack.length(); i++){ if(i + needle.length() > … Read more