Files
dsa-competitive-programming/leetcode/lc20/OptimalParantheses.cpp
T
2026-02-11 14:56:22 +05:30

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();
}
};