Skip to content

Latest commit

 

History

History
19 lines (18 loc) · 418 Bytes

678. Valid Parenthesis String.md

File metadata and controls

19 lines (18 loc) · 418 Bytes
class Solution {
public:
    bool checkValidString(string s) {
        int mn = 0, mx = 0;
        for (const char &c : s) {
            if (c == '(')
                mx++, mn++;
            else if (c == ')')
                mx--, mn = max(mn - 1, 0);
            else if (c == '*')
                mx++, mn = max(mn - 1, 0);
            if (mx < 0) return false;
        }
        return mn == 0;
    }
};