my code was stuck on a stupid test case

  • 0

    Hey my code was stuck on this test case.
    input "a",""
    expected output 0
    my output shown on there is -1.
    But i didn't see any problem of my code, and it comes out the expected out on my IDE
    so What is the problem of my code Can anyone help me with that?

      int strStr(String haystack, String needle) {
            if(haystack.equals(needle)||needle=="") return 0;
            for(int i=0;i<haystack.length()-needle.length()+1;i++){
                for(int j=0;j<needle.length();j++)
                        return i;
            return -1;

Log in to reply

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