Skip to content

Commit 20b239d

Browse files
committed
Added Valid Parenthesis String.java
1 parent 68ecac5 commit 20b239d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Medium/Valid Parenthesis String.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public boolean checkValidString(String s) {
3+
int low = 0;
4+
int high = 0;
5+
for (char c : s.toCharArray()) {
6+
low += c == '(' ? 1 : -1;
7+
high += c != ')' ? 1 : -1;
8+
if (high < 0) {
9+
break;
10+
}
11+
low = Math.max(low, 0);
12+
}
13+
return low == 0;
14+
}
15+
}

0 commit comments

Comments
 (0)