Untitled
user_9124840
plain_text
8 days ago
641 B
1
Indexable
Never
class Solution { public: bool isValid(string s) { stack<char> st; for (char ch : s) { if (ch == '(' || ch == '{' || ch == '[') { st.push(ch); } else { if (st.empty()) return false; if (ch == ')' && st.top() != '(') return false; if (ch == '}' && st.top() != '{') return false; if (ch == ']' && st.top() != '[') return false; st.pop(); } } return st.empty(); } };
Leave a Comment