Javascript solution, easy to understand, maybe not very fast


  • 0
    G

    var isValid = function(s) {
    if(s.length%2 !== 0){return false;}
    while((s.match(/()|[]|{}/g))!==null){
    s = s.replace(/()|[]|{}/g,"");
    }
    if(s.length !== 0){
    return false;
    }
    return true;
    };


Log in to reply
 

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