Leetcode 之Wildcard Matching(32)
跟上题类似,主要考虑‘*’的匹配问题。如果遇到‘*’,则跳过继续匹配,如果不匹配,则s++,重新扫描。
bool isMatch2(const char *s, const char *p) { if (*p == '*') { while (*p == '*')p++; if (*p == '\0')return true; while (*s != '\0' && !isMatch2(s, p))s++; return *s != '\0'; } else if (*p == '\0' || *s == '\0')return *p == *s; else if (*p == *s || *p == '?')return isMatch(++s, ++p); else return false; }