My 7 lines c++ solution


  • 0
    V
    bool isValid(string s) {
        stack<char> sk;
        for(int i=0; i<s.size();i++){
            if(!sk.empty() && s[i]!=sk.top() && abs((int)s[i]-(int)sk.top())<=2) sk.pop();
            else    sk.push(s[i]);
        }
        return sk.empty();
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.