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;
      }
View Code

 

 

posted @ 2016-05-25 16:45  牧马人夏峥  阅读(120)  评论(0编辑  收藏  举报