Skip to content

Commit

Permalink
Time: 1 ms (100.00%), Space: 51.7 MB (83.43%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
rldnrl committed Dec 30, 2022
1 parent 0981394 commit 80f396a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions 0053-maximum-subarray/0053-maximum-subarray.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
class Solution {
public int maxSubArray(int[] nums) {
int maxSub = nums[0];
int answer = nums[0];
int curSum = 0;

for (int num: nums) {
if (curSum < 0) {
curSum = 0;
}
curSum += num;
maxSub = Math.max(maxSub, curSum);
answer = Math.max(curSum, answer);
}

return maxSub;
return answer;
}
}

0 comments on commit 80f396a

Please sign in to comment.