Skip to content

Commit 8d9c1cd

Browse files
committed
Commit
1 parent fc50dc7 commit 8d9c1cd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Leetcode/CheckIfWordisValid.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution {
2+
public:
3+
bool isValid(string S) {
4+
stack<char>s;
5+
6+
int flag=0;
7+
8+
for(int i=0;i<S.length();i++){
9+
if(S[i]=='c'){
10+
if(s.empty())
11+
return false;
12+
else{
13+
if(s.top()=='b'){
14+
s.pop();flag=1;
15+
if(s.empty())
16+
return false;
17+
}
18+
if(flag==0)
19+
return false;
20+
else if(s.top()=='a' && flag==1)
21+
s.pop();
22+
else
23+
return false;
24+
flag=0;
25+
}
26+
}else
27+
s.push(S[i]);
28+
}
29+
30+
return (s.empty());
31+
}
32+
};

0 commit comments

Comments
 (0)