Solution using indexOf()


  • 0
    T

    indexOf returns -1 when needle is not present in haystack.

    public int strStr(String haystack, String needle) {
               int index = haystack.indexOf(needle);
               return index;
        }
    

Log in to reply
 

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