题目

类型:动态规划

难度:简单

最大子序和 - 图1

解题思路

最大子序和 - 图2

动态规划转移方程

最大子序和 - 图3

代码

class Solution {
    public int maxSubArray(int[] nums) {
        int pre = 0, maxAns = nums[0];
        for (int x : nums) {
            pre = Math.max(pre + x, x);
            maxAns = Math.max(maxAns, pre);
        }
        return maxAns;
    }
}