forked from v100901/hackoctoberfest2020__
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalid_paranthesis.cpp
More file actions
35 lines (33 loc) · 863 Bytes
/
valid_paranthesis.cpp
File metadata and controls
35 lines (33 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool isValid(string s) {
stack<char> m;
for(auto& ch:s){
if(ch=='('||ch=='{'||ch=='[')
m.push(ch);
else if(ch==')'){
if(m.empty()||m.top()!='(')
return false;
m.pop();
}
else if(ch=='}'){
if(m.empty()||m.top()!='{')
return false;
m.pop();
}
else if(ch==']'){
if(m.empty()||m.top()!='[')
return false;
m.pop();
}
}
return m.empty();
}
int main()
{
string s;
cin>>s;
cout<<isValid(s);
return 0;
}