diff --git a/678. Valid Parenthesis String b/678. Valid Parenthesis String new file mode 100644 index 0000000..ce5b34a --- /dev/null +++ b/678. Valid Parenthesis String @@ -0,0 +1,19 @@ +#include +#include +#include + +using namespace std; + +class Solution { +public: + bool checkValidString(string s) { + int low = 0, high = 0; + for (char c : s) { + low += (c == '(') ? 1 : -1; + high += (c != ')') ? 1 : -1; + if (high < 0) return false; + low = max(low, 0); + } + return low == 0; + } +};