TLE for largest input.


  • 0
    G
     My code works for every input except the largest input where I am getting TLE.   
      bool match(const char *first, const char * second)
        {
            // If we reach at the end of both strings, we are done
            if (*first == '\0' && *second == '\0')
                return true;
         
            // Make sure that the characters after '*' are present in second string.
            // This function assumes that the first string will not contain two
            // consecutive '*'
            if (*first == '*' && *(first+1) != '\0' && *second == '\0')
                return false;
         
            // If the first string contains '?', or current characters of both
            // strings match
            if (*first == '?' || *first == *second)
                return match(first+1, second+1);
         
            // If there is *, then there are two possibilities
            // a) We consider current character of second string
            // b) We ignore current character of second string.
            if (*first == '*')
               {
                 while(*(first+1)=='*') 
                   first = first +1;
                 return match(first+1, second) || match(first, second+1);
               }    
            return false;
        }
        
            bool isMatch(const char *s, const char *p) {
                  
                  return match(p, s);
            }

Log in to reply
 

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