run code good but a different way when submit my c program


  • 0
    Y
    bool match(char a, char p) {
    	if (p == '.')return true;
    	return a == p;
    }
    bool isMatch(char* s, char* p) {
    	if (*p == 0) {
    		return *s == 0;
    	}
    	if (*s == 0) {
    		while (*(p + 1) == '*') {
    			p += 2;
    		}
    		return *p == 0;
    	}
    	if (*(p + 1) == '*') {
    		if (isMatch(s, p + 2)) {
    			return true;
    		}
    		if (!match(*s, *p))
    			return isMatch(s, p + 2);
    		return isMatch(s + 1, p);
    
    	}
    	else {
    		if (!match(*s, *p))
    			return false;
    		return isMatch(s + 1, p + 1);
    	}
    }
    

    0_1473242672630_新建位图图像.bmp
    0_1473242724882_新建位图图像.bmp


  • 0
    Y

    my compiler also gives the correct answer, not really understand what was happening


  • 0
    Y

    thanks to previous discussions i finally found out where the problem is.
    and modified as follows

    	if (*s == 0) {
    		while (*p != 0 && *(p + 1) == '*') {
    			p += 2;
    		}
    		return *p == 0;
    	}

Log in to reply
 

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