Skip to content

Commit 1eda5c1

Browse files
Create 678. Valid Parenthesis String.cpp
solution of the problem
1 parent fb9fd2f commit 1eda5c1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

678. Valid Parenthesis String.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
bool checkValidString(string s) {
4+
int min=0,max=0;
5+
for(int i=0;i<s.size();i++){
6+
if(s[i]=='('){
7+
min++;
8+
max++;
9+
}else if(s[i]==')'){
10+
min--;
11+
max--;
12+
}else{
13+
min--;
14+
max++;
15+
}
16+
if(min<0) min = 0;
17+
if(max<0) return false;
18+
}
19+
return min==0;
20+
}
21+
};

0 commit comments

Comments
 (0)