Run my computer is right but wrong in leetcode with same input

  • 0

    int strStr(char* haystack, char* needle) { //needle is substring of haystack or not

    int lh=strlen(haystack);
    int ln=strlen(needle);
    if(ln>lh) return -1;
    char *bijiao="";
    if(!strcmp(bijiao,needle)) return 0;
    if(!strcmp(haystack,needle)) return 0;
    char tmp[ln+1],first=needle[0];
    int i;
    { strncpy(tmp,&haystack[i],ln);
    if(strcmp(needle,tmp)==0) return i;



    return -1;


Log in to reply

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