Skip to content

Commit 390990b

Browse files
authored
feat: add solutions to lc problem: No.1413 (doocs#604)
No.1413.Minimum Value to Get Positive Step by Step Sum
1 parent 36ab4ab commit 390990b

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum/README.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,31 @@
6565
<!-- 这里可写当前语言的特殊实现逻辑 -->
6666

6767
```python
68-
68+
class Solution:
69+
def minStartValue(self, nums: List[int]) -> int:
70+
s, t = 0, float('inf')
71+
for num in nums:
72+
s += num
73+
t = min(t, s)
74+
return max(1, 1 - t)
6975
```
7076

7177
### **Java**
7278

7379
<!-- 这里可写当前语言的特殊实现逻辑 -->
7480

7581
```java
76-
82+
class Solution {
83+
public int minStartValue(int[] nums) {
84+
int s = 0;
85+
int t = Integer.MAX_VALUE;
86+
for (int num : nums) {
87+
s += num;
88+
t = Math.min(t, s);
89+
}
90+
return Math.max(1, 1 - t);
91+
}
92+
}
7793
```
7894

7995
### **...**

solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum/README_EN.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,29 @@
9696
### **Python3**
9797

9898
```python
99-
99+
class Solution:
100+
def minStartValue(self, nums: List[int]) -> int:
101+
s, t = 0, float('inf')
102+
for num in nums:
103+
s += num
104+
t = min(t, s)
105+
return max(1, 1 - t)
100106
```
101107

102108
### **Java**
103109

104110
```java
105-
111+
class Solution {
112+
public int minStartValue(int[] nums) {
113+
int s = 0;
114+
int t = Integer.MAX_VALUE;
115+
for (int num : nums) {
116+
s += num;
117+
t = Math.min(t, s);
118+
}
119+
return Math.max(1, 1 - t);
120+
}
121+
}
106122
```
107123

108124
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int minStartValue(int[] nums) {
3+
int s = 0;
4+
int t = Integer.MAX_VALUE;
5+
for (int num : nums) {
6+
s += num;
7+
t = Math.min(t, s);
8+
}
9+
return Math.max(1, 1 - t);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def minStartValue(self, nums: List[int]) -> int:
3+
s, t = 0, float('inf')
4+
for num in nums:
5+
s += num
6+
t = min(t, s)
7+
return max(1, 1 - t)

0 commit comments

Comments
 (0)