javascript-solution
1.solution
var countAndSay = function(n) {
res=""
oldAry = [];
oldAry.push(1)
ary = [];
ary.push(1)
round = 0;
count = 1;
index = 0;
len = 1;
while(round < n-1){
round++;
index = 0
for(i = 0 ; i < len; i++){
if (oldAry[i] === oldAry[i+1] )
{
count++
}else{
ary[index++] = count;
ary[index++] = oldAry[i];
count = 1;
}
}
len = index ;
oldAry=ary.slice(0)
}
ary.forEach(function(element, index, array){
res+=element
})
return res
};
2.performance
Last updated
Was this helpful?