Why my code get timeout?


  • 0
    W

    char *strStr(char *haystack, char *needle) {
    char *tmp_h, *tmp_n;

    	if( haystack==NULL || needle==NULL ) return NULL;
        if( *haystack=='\0' && *needle=='\0' ) return haystack;
    
        while( *haystack!='\0' ) {
            tmp_n = needle;
            tmp_h = haystack;
            while( *tmp_n!='\0' && *tmp_h!='\0' && *tmp_n==*(tmp_h++) ) tmp_n++;
                
            if( *tmp_n=='\0' ) return haystack;
                
            haystack++;
        }
            
        return NULL;
    }

Log in to reply
 

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