7-line java solution


  • 0
    S
        public int strStr(String haystack, String needle) {
            int len = needle.length();
            for(int i = 0; i <= haystack.length()-len; i++)
                if (haystack.substring(i, i+len).equals(needle))
                    return i;
            return -1;
        }
    

Log in to reply
 

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