Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimized and simplified #281

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
optimized and simplified
  • Loading branch information
danyaobertan authored Feb 5, 2024
commit c5bcb82ce776d74dcc8b99a0de12ce133d08652b
11 changes: 3 additions & 8 deletions leetcode/0066.Plus-One/66. Plus One.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ package leetcode

func plusOne(digits []int) []int {
for i := len(digits) - 1; i >= 0; i-- {
digits[i]++
if digits[i] != 10 {
// no carry
if digits[i] != 9 {
digits[i]++
return digits
}
// carry
digits[i] = 0
}
// all carry
digits[0] = 1
digits = append(digits, 0)
return digits
return append([]int{1}, digits...)
}