Skip to content

Commit

Permalink
Merge pull request neetcode-gh#988 from MaratKhakim/66-Plus-One-kt
Browse files Browse the repository at this point in the history
Kotlin: 66. Plus One
  • Loading branch information
Ahmad-A0 authored Sep 2, 2022
2 parents 1613176 + ef93c0b commit 40c55f2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kotlin/66-Plus-One.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
fun plusOne(digits: IntArray): IntArray {
for (i in digits.size-1 downTo 0) {
digits[i] += 1

if (digits[i] <= 9)
return digits

digits[i] = 0
}

return IntArray(digits.size+1).also{ it[0] = 1 }
}
}

0 comments on commit 40c55f2

Please sign in to comment.