A trick with ASCII Code


  • 0
    M
    bool isValid(string s) {
            stack<int> temp;
            for(int i=0;i<s.size();i++) {
                if(!temp.empty()&&temp.top()<s[i]&&s[i]-temp.top()<3) {
                    temp.pop();
                    continue;
                }
                temp.push(s[i]);
            }
            return temp.empty();
        }

Log in to reply
 

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