File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 15
15
16
16
public class _53 {
17
17
18
- public static class Solution1 {
19
- /**credit: https://discuss.leetcode.com/topic/5000/accepted-o-n-solution-in-java*/
20
- public int maxSubArray (int [] nums ) {
21
- int maxSoFar = nums [0 ];
22
- int maxEndingHere = nums [0 ];
23
- for (int i = 1 ; i < nums .length ; i ++) {
24
- maxEndingHere = Math .max (nums [i ], maxEndingHere + nums [i ]);
25
- maxSoFar = Math .max (maxEndingHere , maxSoFar );
18
+ public static class Solution1 {
19
+ /**
20
+ * https://leetcode.com/problems/maximum-subarray/discuss/20211/accepted-on-solution-in-java
21
+ */
22
+ public int maxSubArray (int [] nums ) {
23
+ int maxSoFar = nums [0 ];
24
+ int maxEndingHere = nums [0 ];
25
+ for (int i = 1 ; i < nums .length ; i ++) {
26
+ maxEndingHere = Math .max (nums [i ], maxEndingHere + nums [i ]);
27
+ maxSoFar = Math .max (maxEndingHere , maxSoFar );
28
+ }
29
+ return maxSoFar ;
26
30
}
27
- return maxSoFar ;
28
31
}
29
- }
30
32
}
You can’t perform that action at this time.
0 commit comments