leetcode

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

0678.cpp (445B)


      1 class Solution {
      2   public:
      3     bool checkValidString(const string &s) const {
      4         int mini = 0, maxi = 0;
      5         for (const char c : s) {
      6             if (c == '(')
      7                 mini++, maxi++;
      8             else if (c == ')')
      9                 mini--, maxi--;
     10             else if (c == '*')
     11                 maxi++, mini--;
     12             if (maxi < 0) return false;
     13             mini = max(mini, 0);
     14         }
     15         return mini == 0;
     16     }
     17 };