52 ms Javascript solution beats 99% of JS solutions


  • 0

    '''
    var isValid = function(s) {
    var stack = [];
    for (var i=0; i<s.length; i++) {
    if(s[i] == '(') {
    stack.push(')');
    }
    else if(s[i] == '{') {
    stack.push('}');
    }
    else if(s[i] == '[') {
    stack.push(']');
    }
    else if(stack.length == 0 || s[i] != stack.pop()) {
    return false;
    }
    }
    if(stack.length == 0) {
    return true;
    }
    else {
    return false;
    }
    };
    '''


Log in to reply
 

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