Why can't we use String indexOf() function ?


  • 0
    O

    Simple implementation using String indexOf() function

    public int strStr(String haystack, String needle) {
            if(needle == null || haystack == null) return -1;
            if(needle.length() > haystack.length()) return -1;
            return haystack.indexOf(needle);
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.