4 lines code, 6ms, Java solution


  • 0
    Y

    Using java buildin function Contains and indexOf

        public int strStr(String haystack, String needle) {
            if(haystack.contains(needle))
                return haystack.indexOf(needle);
            else
                return -1;
        }
    

Log in to reply
 

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