valid parentheses : what's this error?
#include<bits/stdc++.h> 
#include <stack>
class Solution {
public:
    bool isValid(string s) {
        stack <char> st;
        char x;
        
        for (int i=0;i<s.length();i++)
        {
            if (s[i]=='(' || s[i]=='{' || s[i]=='[')
            {
                st.push(s[i]);
                continue;
            }
            
            if(s.empty())
                return false;
            
            switch(s[i])
            {
                case ')' :
                    x=st.top();
                    st.pop();
                    if (x=='}' || x==']')
                        return false;
                        break;
                    
                case '}' :
                    x=st.top();
                    st.pop();
                    if(x==')' || x==']')
                        return false;
                        break;
                    
                case ']' :
                    x=st.top();
                    st.pop();
                    if(x==')' || x=='}')
                        return false;
                        break;
            }
        }
        
        if(st.empty())
            return true;
    }
};
Comments (1)