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 3200de1 commit c5bcb82Copy full SHA for c5bcb82
leetcode/0066.Plus-One/66. Plus One.go
@@ -2,16 +2,11 @@ package leetcode
2
3
func plusOne(digits []int) []int {
4
for i := len(digits) - 1; i >= 0; i-- {
5
- digits[i]++
6
- if digits[i] != 10 {
7
- // no carry
+ if digits[i] != 9 {
+ digits[i]++
8
return digits
9
}
10
- // carry
11
digits[i] = 0
12
13
- // all carry
14
- digits[0] = 1
15
- digits = append(digits, 0)
16
- return digits
+ return append([]int{1}, digits...)
17
0 commit comments