minimum-value-to-get-positive-step-by-step-sum
This commit is contained in:
parent
47b81f8c68
commit
2c0204028e
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue