Skip to content

Commit 24f69c2

Browse files
add solution 038[js]
1 parent a8bd328 commit 24f69c2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const countAndSay = function(n){
2+
let s = '1';
3+
4+
for(let i = 2; i <= n; i++){
5+
let count = 1, str = '', len = s.length;
6+
7+
for(let j = 0 ; j < len; j++){
8+
if(j < len - 1 && s[j] === s[j + 1]){
9+
count++;
10+
}else{
11+
str += `${count}${s[j]}`;
12+
count = 1;
13+
}
14+
}
15+
s = str;
16+
}
17+
return s;
18+
}

0 commit comments

Comments
 (0)