给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
算法:动态规划class Solution {
public int maxSubArray(int[] nums) {
int pre = 0;
int max = nums[0];
for (int num : nums) {
pre = Math.max(num, pre + num);
max = Math.max(max, pre);
}
return max;
}
}
力扣连接:[https://leetcode-cn.com/problems/maximum-subarray/]



