0ms C++ solution, Shortest code you can find!


  • 2
    D
    bool isValid(string s) {
        stack<char> stack; map<char,char> map;
        map[')']='(';map['}']='{';map[']']='[';
        for(char c:s)
        {
            if(map.find(c)!=map.end())
                if(!stack.empty() && stack.top()==map[c])
                stack.pop();
                else
                return false;
            else
            stack.push(c);
        }
        return stack.empty();
    }

  • 0

    You're saying I can't find my code?


Log in to reply
 

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