publicintmaxSubArray(int[] nums){int max =Integer.MIN_VALUE, pre =0;for(int num : nums){
pre = pre <0? num : pre + num;
max =Math.max(max, pre);}return max;}
publicintmaxProduct(int[] nums){int ans = nums[0], max = ans, min = ans;for(int i =1; i < nums.length; i++){int mx =Math.max(nums[i],Math.max(max * nums[i], min * nums[i]));int mn =Math.min(nums[i],Math.min(max * nums[i], min * nums[i]));
max = mx;
min = mn;
ans =Math.max(ans, max);}return ans;}