Skip to content

Commit 755a89a

Browse files
authored
Create 1291-sequential-digits.kt
1 parent 8a2fea5 commit 755a89a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

kotlin/1291-sequential-digits.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
fun sequentialDigits(low: Int, high: Int): List<Int> {
3+
var q = mutableListOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
4+
var res = mutableListOf<Int>()
5+
6+
while (q.isNotEmpty()) {
7+
var n = q.removeFirst()
8+
9+
if (n > high) continue
10+
if (n >= low) res.add(n)
11+
12+
val d = n % 10
13+
if (d < 9) q.add(n * 10 + (d + 1))
14+
}
15+
16+
return res
17+
}
18+
}

0 commit comments

Comments
 (0)