Skip to content

Commit 90e75ad

Browse files
refactor 53
1 parent 933ae89 commit 90e75ad

File tree

1 file changed

+12
-10
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+12
-10
lines changed

src/main/java/com/fishercoder/solutions/_53.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515

1616
public class _53 {
1717

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;
2630
}
27-
return maxSoFar;
2831
}
29-
}
3032
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy