Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions 678. Valid Parenthesis String
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <iostream>
#include <string>
#include <algorithm>

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