leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0044.cpp (599B)


      1 class Solution {
      2   public:
      3     bool isMatch(string s, string p) {
      4         int i = 0, j = 0, n = s.size(), m = p.size();
      5         int last = -1, star = -1;
      6         while (i < n) {
      7             if (j < m && (s[i] == p[j] || p[j] == '?'))
      8                 i++, j++;
      9             else if (j < m && p[j] == '*') {
     10                 star = j++;
     11                 last = i;
     12             } else if (star != -1) {
     13                 j = star + 1;
     14                 i = ++last;
     15             } else
     16                 return false;
     17         }
     18         while (p[j] == '*' && j < m)
     19             j++;
     20         return j == m;
     21     }
     22 };