53 Maximum Subarray – Medium
Problem:
Thoughts:
Solutions:
public class Solution {
public int maxSubArray(int[] nums) {
int currSum = 0;
int max = Integer.MIN_VALUE;
for (int i = 0; i < nums.length; i ++) {
currSum = Math.max(currSum + nums[i], nums[i]);
max = Math.max(currSum, max);
}
return max;
}
}Last updated