This question is different from Regular Expression Matching.
Because this does not need totally match. We just have to much p is part of s.
1 class Solution { 2 public: 3 bool isMatch(const char *s, const char *p) { 4 const char *olds = s, *oldp = p; 5 bool star = false; 6 while (*s) { 7 if (*s != *p) { 8 if (*p == '?') { 9 s++, p++; 10 } else if (*p == '*') { 11 while (*p == '*') p++; 12 if (*p == '\0') return true; 13 star = true; 14 olds = s, oldp = p; 15 } else if (star) { 16 olds++; 17 s = olds, p = oldp; 18 } else return false; 19 } else s++, p++; 20 } 21 while (*p == '*') p++; 22 return *p == '\0'; 23 } 24 };