Skip to content

Commit 7aca5c4

Browse files
authored
Create Valid Paranthesis
1 parent ef5fd44 commit 7aca5c4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Strings/Valid Paranthesis

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//Leetcode
2+
3+
class Solution {
4+
public:
5+
bool isValid(string s) {
6+
stack<char>st;
7+
for(int i = 0;i<s.size();i++){
8+
if(s[i]=='(' || s[i]=='{' || s[i]=='['){
9+
st.push(s[i]);
10+
}
11+
else{
12+
if(!st.empty() &&((s[i]==')' && st.top()=='(')||(s[i]==']' && st.top()=='[')||(s[i]=='}' && st.top()=='{'))){
13+
st.pop();
14+
}
15+
else{
16+
return false;
17+
}
18+
}
19+
}
20+
if(!st.empty()){
21+
return false;
22+
}
23+
else return true;
24+
}
25+
};

0 commit comments

Comments
 (0)