minimum-value-to-get-positive-step-by-step-sum

This commit is contained in:
Gleb Koval 2021-11-12 09:53:39 +00:00
parent 47b81f8c68
commit 2c0204028e
No known key found for this signature in database
GPG Key ID: 7C89CDC822F8392B
1 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package main
func minStartValue(nums []int) int {
min, s := nums[0], 0
for i := range nums {
s += nums[i]
if s < min {
min = s
}
}
if min > 0 {
return 1
}
return 1 - min
}