Skip to content

Commit 437cc53

Browse files
solves minimum value to get to positive step sum
1 parent df9fc4f commit 437cc53

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@
358358
| 1399 | [Count Largest Group](https://leetcode.com/problems/count-largest-group) | [![Java](assets/java.png)](src/CountLargestGroup.java) | |
359359
| 1403 | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order) | [![Java](assets/java.png)](src/MinimumSubSequenceInNonIncreasingOrder.java) | |
360360
| 1408 | [String Matching In An Array](https://leetcode.com/problems/string-matching-in-an-array) | [![Java](assets/java.png)](src/StringMatchingInAnArray.java) | |
361-
| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | | |
361+
| 1413 | [Minimum Value To Get Positive Step By Step Sum](https://leetcode.com/problems/minimum-value-to-get-positive-step-by-step-sum) | [![Java](assets/java.png)](src/MinimumValueToGetPositiveStepByStepSum.java) | |
362362
| 1417 | [Reformat The String](https://leetcode.com/problems/reformat-the-string) | | |
363363
| 1422 | [Maximum Score After Splitting A String](https://leetcode.com/problems/maximum-score-after-splitting-a-string) | | |
364364
| 1426 | [Counting Elements](https://leetcode.com/problems/counting-elements) | | |

Diff for: src/MinimumValueToGetPositiveStepByStepSum.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class MinimumValueToGetPositiveStepByStepSum {
2+
public int minStartValue(int[] array) {
3+
int lowestPoint =getLowestPoint(array);
4+
return 1 - Math.min(0, lowestPoint);
5+
}
6+
7+
private int getLowestPoint(int[] array) {
8+
int lowestPoint = 0, sum = 0;
9+
for (int element : array) {
10+
sum += element;
11+
if (sum < lowestPoint) lowestPoint = sum;
12+
}
13+
return lowestPoint;
14+
}
15+
}

0 commit comments

Comments
 (0)