Skip to content

Commit 1a2411a

Browse files
authored
Create 1413-minimum-value-to-get-positive-step-by-step-sum.js
1 parent 9562bfa commit 1a2411a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const minStartValue = function(nums) {
6+
let sum = 0, min = Infinity
7+
for(let e of nums) {
8+
sum += e
9+
min = Math.min(min, sum)
10+
}
11+
12+
return min >= 0 ? 1 : -min + 1
13+
};

0 commit comments

Comments
 (0)