Javascript elegant solution


  • 0
    L
    var isValid = function(s) {
        while(s.match(/\(\)|\[\]|\{\}/g)){
            s = s.split('()').join('').split('[]').join('').split('{}').join('');
        }
        if(!s) return true;
        return false;
    };

  • 1
    C
    if(!s) return true;
        return false;
    

    can be simplified as

    return !s
    

    Also,I wonder if the following cases should be handled? ex: { ( [ ] ) } or { () }


Log in to reply
 

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