MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / plusOne

Function plusOne

plus_one_66/solution.go:3–22  ·  view source on GitHub ↗
(digits []int)

Source from the content-addressed store, hash-verified

1package plus_one_66
2
3func plusOne(digits []int) []int {
4 carry := 1
5 for i := len(digits) - 1; i >= 0; i-- {
6 incr := digits[i] + carry
7
8 if incr == 10 {
9 digits[i] = 0
10 carry = 1
11 } else {
12 digits[i] = incr
13 carry = 0
14 }
15 }
16
17 if carry == 1 {
18 return append([]int{1}, digits...)
19 }
20
21 return digits
22}

Callers 1

Test_plusOneFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_plusOneFunction · 0.68