File tree 4 files changed +54
-4
lines changed
solution/1400-1499/1413.Minimum Value to Get Positive Step by Step Sum
4 files changed +54
-4
lines changed Original file line number Diff line number Diff line change 65
65
<!-- 这里可写当前语言的特殊实现逻辑 -->
66
66
67
67
``` 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)
69
75
```
70
76
71
77
### ** Java**
72
78
73
79
<!-- 这里可写当前语言的特殊实现逻辑 -->
74
80
75
81
``` 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
+ }
77
93
```
78
94
79
95
### ** ...**
Original file line number Diff line number Diff line change 96
96
### ** Python3**
97
97
98
98
``` 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)
100
106
```
101
107
102
108
### ** Java**
103
109
104
110
``` 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
+ }
106
122
```
107
123
108
124
### ** ...**
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments