678. Valid Parenthesis String
https://leetcode.com/problems/valid-parenthesis-string/
/*
* @lc app=leetcode id=678 lang=cpp
*
* [678] Valid Parenthesis String
*/
// @lc code=start
class Solution {
public:
bool checkValidString(string s) {
int min_op = 0, max_op = 0;
for (const auto c : s) {
if (c == '(') ++min_op;
else --min_op;
if (c != ')') ++max_op;
else --max_op;
if (max_op < 0) return false;
min_op = max(0, min_op);
}
return min_op == 0;
}
};
// @lc code=end
Last updated