Skip to content

Commit

Permalink
Create 1291-sequential-digits.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
a93a authored Feb 2, 2024
1 parent 8a2fea5 commit 755a89a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions kotlin/1291-sequential-digits.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
fun sequentialDigits(low: Int, high: Int): List<Int> {
var q = mutableListOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
var res = mutableListOf<Int>()

while (q.isNotEmpty()) {
var n = q.removeFirst()

if (n > high) continue
if (n >= low) res.add(n)

val d = n % 10
if (d < 9) q.add(n * 10 + (d + 1))
}

return res
}
}

0 comments on commit 755a89a

Please sign in to comment.