mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
19 lines
513 B
C++
19 lines
513 B
C++
class Solution{
|
|
public:
|
|
bool isValid(string s){
|
|
stack<char> st;
|
|
for(char c : s){
|
|
if(c=='(' || c == '{' || c == '[') st.push(c);
|
|
else{
|
|
if(st.empty()) return false;
|
|
|
|
char top = st.top();
|
|
st.pop();
|
|
|
|
if((c==')' && top!='(') || (c == '}' && top!= '{') || (c == ']' && top!= '[')) return false;
|
|
}
|
|
}
|
|
return st.empty();
|
|
}
|
|
};
|