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;
}
};