Skip to content

Commit 70b0050

Browse files
authored
Create 678. Valid Parenthesis String (#450)
2 parents 21c80fe + 0c5f8be commit 70b0050

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

678. Valid Parenthesis String

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
class Solution {
8+
public:
9+
bool checkValidString(string s) {
10+
int low = 0, high = 0;
11+
for (char c : s) {
12+
low += (c == '(') ? 1 : -1;
13+
high += (c != ')') ? 1 : -1;
14+
if (high < 0) return false;
15+
low = max(low, 0);
16+
}
17+
return low == 0;
18+
}
19+
};

0 commit comments

Comments
 (0)