20. Valid Parentheses - cocoder39/coco39_LC GitHub Wiki

20. Valid Parentheses

bool isValid(string s) {
        stack<char> st;
        for (auto c : s) {
            if (c == '(' || c == '{' || c == '[') {
                st.push(c);
            } else if (st.empty()) {
                return false;
            } else if ((c == ')' && st.top() == '(') || (c == '}' && st.top() == '{') ||
                       (c == ']' && st.top() == '[')) {
                st.pop();
            } else {
                return false;
            }
        }
        return st.empty(); 
    }
⚠️ **GitHub.com Fallback** ⚠️