leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0044.cpp (599B)
0 class Solution { 1 public: 2 bool isMatch(string s, string p) { 3 int i = 0, j = 0, n = s.size(), m = p.size(); 4 int last = -1, star = -1; 5 while (i < n) { 6 if (j < m && (s[i] == p[j] || p[j] == '?')) 7 i++, j++; 8 else if (j < m && p[j] == '*') { 9 star = j++; 10 last = i; 11 } else if (star != -1) { 12 j = star + 1; 13 i = ++last; 14 } else 15 return false; 16 } 17 while (p[j] == '*' && j < m) 18 j++; 19 return j == m; 20 } 21 };