JavaScript solution using replace


  • 0
    1
    var isValid = function(s) {
        if(s.length % 2 !== 0){
            return false;   
        }
        
        var temp = '';
        while(temp !== s){
            temp = s;
            s = s.replace(/\[\]/g,'').replace(/\(\)/g,'').replace(/\{\}/g,'');
        }
        return s === '';
    };
    

Log in to reply
 

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