From 03803a65f532061e1f97da665353f6a0d9aff596 Mon Sep 17 00:00:00 2001 From: CyC2018 <1029579233@qq.com> Date: Thu, 1 Mar 2018 21:31:51 +0800 Subject: [PATCH] auto commit --- notes/Leetcode 题解.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/notes/Leetcode 题解.md b/notes/Leetcode 题解.md index c2a27104..990145c2 100644 --- a/notes/Leetcode 题解.md +++ b/notes/Leetcode 题解.md @@ -2379,11 +2379,13 @@ class NumArray { ```java public int maxSubArray(int[] nums) { - int max = nums[0]; - int oldsum = nums[0]; - for (int i = 1; i < nums.length; i++) { - oldsum = (oldsum > 0 ? oldsum: 0) + nums[i]; - max = Math.max(max, oldsum); + int n = nums.length; + int[] sum = new int[n]; + sum[0] = nums[0]; + int max = sum[0]; + for(int i = 1; i < n; i++){ + sum[i] = (sum[i-1] > 0 ? sum[i-1] : 0) + nums[i]; + max = Math.max(max, sum[i]); } return max; }