Problem Statement
Pattern: Pattern Kadane’s Algorithm
Solution
public static int maxSubArray (int[] nums){
int max = Integer.MIN_VALUE, currMax = Integer.MIN_VALUE;
for (int num : nums) {
if (currMax <= 0) currMax = num;
else currMax += num;
max = Math.max(max, currMax);
}
return max;
}