8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e4f3833 commit 197d77cCopy full SHA for 197d77c
0038-count-and-say/0038-count-and-say.kt
@@ -0,0 +1,32 @@
1
+class Solution {
2
+ fun countAndSay(n: Int): String {
3
+ var result = "1"
4
+
5
+ repeat(n - 1) {
6
+ val newResult = StringBuilder()
7
8
+ var count = 1
9
+ var prev = result[0].digitToInt()
10
11
+ for (i in 1 until result.length) {
12
+ val num = result[i].digitToInt()
13
+ if (num == prev) {
14
+ ++count
15
+ }
16
+ else {
17
+ newResult.append(count)
18
+ newResult.append(prev)
19
20
+ prev = num
21
+ count = 1
22
23
24
25
26
27
+ result = newResult.toString()
2 4B84 8
29
30
+ return result
31
32
+}
0 commit comments