My JavaScript Solution


  • 0
    B
    var countAndSay = function(n) {
        var str = "1", newstr = "";
        for(var i = 1; i < n; i++) {
            var s = 1;
            for(var j = 0; j < str.length; j++) {
                if(str.charAt(j) === str.charAt(j+1)) {
                    s++;
                } else {
                    newstr += s + str.charAt(j);
                    s = 1;
                }
            }
            str = newstr;
            newstr = "";
        }
        return str;
    };
    

Log in to reply
 

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