forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4bd167
commit 7dc6a98
Showing
7 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum/1413.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Solution { | ||
public: | ||
int minStartValue(vector<int>& nums) { | ||
int pref = 0, min_pref = 0; | ||
for (int i : nums) { | ||
pref += i; | ||
min_pref = min(min_pref, pref); | ||
} | ||
return 1 - min_pref; | ||
} | ||
}; |
15 changes: 15 additions & 0 deletions
15
src/1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum/1413.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
func minStartValue(nums []int) int { | ||
pref, min_pref := 0, 0 | ||
for _, i := range nums { | ||
pref += i | ||
min_pref = min(min_pref, i) | ||
} | ||
return 1 - min_pref | ||
} | ||
|
||
func min(a, b int) int { | ||
if a < b { | ||
return a | ||
} | ||
return b | ||
} |
10 changes: 10 additions & 0 deletions
10
src/1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum/1413.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Solution { | ||
public int minStartValue(int[] nums) { | ||
int pref = 0, min_pref = 0; | ||
for (int i : nums) { | ||
pref += i; | ||
min_pref = Math.min(min_pref, pref); | ||
} | ||
return 1 - min_pref; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum/1413.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
var minStartValue = function(nums) { | ||
let pref = 0, min_pref = 0; | ||
for (let i of nums) { | ||
pref += i; | ||
min_pref = Math.min(min_pref, pref); | ||
} | ||
return 1 - min_pref; | ||
}; |
7 changes: 7 additions & 0 deletions
7
src/1413-Minimum-Value-to-Get-Positive-Step-by-Step-Sum/1413.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Solution: | ||
def minStartValue(self, nums: List[int]) -> int: | ||
pref, min_pref = 0, 0 | ||
for i in nums: | ||
pref += i | ||
min_pref = min(min_pref, pref) | ||
return 1 - min_pref |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters