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