Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5b9be55

Browse files
committed
Add solution #1413
1 parent 8a4ab08 commit 5b9be55

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,288 LeetCode solutions in JavaScript
1+
# 1,289 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1079,6 +1079,7 @@
10791079
1409|[Queries on a Permutation With Key](./solutions/1409-queries-on-a-permutation-with-key.js)|Medium|
10801080
1410|[HTML Entity Parser](./solutions/1410-html-entity-parser.js)|Medium|
10811081
1411|[Number of Ways to Paint N × 3 Grid](./solutions/1411-number-of-ways-to-paint-n-3-grid.js)|Hard|
1082+
1413|[Minimum Value to Get Positive Step by Step Sum](./solutions/1413-minimum-value-to-get-positive-step-by-step-sum.js)|Easy|
10821083
1415|[The k-th Lexicographical String of All Happy Strings of Length n](./solutions/1415-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n.js)|Medium|
10831084
1422|[Maximum Score After Splitting a String](./solutions/1422-maximum-score-after-splitting-a-string.js)|Easy|
10841085
1431|[Kids With the Greatest Number of Candies](./solutions/1431-kids-with-the-greatest-number-of-candies.js)|Easy|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* 1413. Minimum Value to Get Positive Step by Step Sum
3+
* https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum/
4+
* Difficulty: Easy
5+
*
6+
* Given an array of integers nums, you start with an initial positive value startValue.
7+
*
8+
* In each iteration, you calculate the step by step sum of startValue plus elements in
9+
* nums (from left to right).
10+
*
11+
* Return the minimum positive value of startValue such that the step by step sum is never
12+
* less than 1.
13+
*/
14+
15+
/**
16+
* @param {number[]} nums
17+
* @return {number}
18+
*/
19+
var minStartValue = function(nums) {
20+
let minSum = 0;
21+
let currentSum = 0;
22+
23+
for (const num of nums) {
24+
currentSum += num;
25+
minSum = Math.min(minSum, currentSum);
26+
}
27+
28+
return Math.max(1, 1 - minSum);
29+
};

0 commit comments

Comments
 (0)