with regex


  • 0
    L
    var decodeString = function(s) {
        s = s.replace(/(\d+)\[(\w+)\]/g, function($0, $1, $2) {
            return (new Array(+$1 + 1)).join($2);
        });
            
        return /\[/.test(s) ? decodeString(s) : s;
     };
    

Log in to reply
 

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