Short and clear code (16 line)


  • 1
    W
    class Solution {
    public:
        bool isMatch(const char *s, const char *p) {
            while (*s || *p) {
                if (p[0] && p[1] == '*')
                    return isMatch(s, p+2) || comp(*s, *p) && isMatch(s+1, p);
                else 
                    if (!comp(*s++, *p++)) return false;
            }
            return true;
        }
        
        inline bool comp(char a, char b) {
            return a && b && (a==b || b=='.');
        }
    };
    

    :)


Log in to reply
 

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