mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
规范格式
This commit is contained in:
21
leetcode/0066.Plus-One/66. Plus One.go
Normal file
21
leetcode/0066.Plus-One/66. Plus One.go
Normal file
@ -0,0 +1,21 @@
|
||||
package leetcode
|
||||
|
||||
func plusOne(digits []int) []int {
|
||||
if len(digits) == 0 {
|
||||
return []int{}
|
||||
}
|
||||
carry := 1
|
||||
for i := len(digits) - 1; i >= 0; i-- {
|
||||
if digits[i]+carry > 9 {
|
||||
digits[i] = 0
|
||||
carry = 1
|
||||
} else {
|
||||
digits[i] += carry
|
||||
carry = 0
|
||||
}
|
||||
}
|
||||
if digits[0] == 0 && carry == 1 {
|
||||
digits = append([]int{1}, digits...)
|
||||
}
|
||||
return digits
|
||||
}
|
Reference in New Issue
Block a user