From f293d704d1c6d39b7decf16d89f86dc3c8f0fa5c Mon Sep 17 00:00:00 2001 From: CyC2018 <1029579233@qq.com> Date: Thu, 1 Mar 2018 21:24:43 +0800 Subject: [PATCH] auto commit --- notes/Leetcode 题解.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/notes/Leetcode 题解.md b/notes/Leetcode 题解.md index fb9d66b3..990145c2 100644 --- a/notes/Leetcode 题解.md +++ b/notes/Leetcode 题解.md @@ -2391,6 +2391,20 @@ public int maxSubArray(int[] nums) { } ``` +空间复杂度可以优化成 O(1) 空间复杂度 + +```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); + } + return max; +} +``` + **数组中等差递增子区间的个数** [Leetcode : 413. Arithmetic Slices (Medium)](https://leetcode.com/problems/arithmetic-slices/description/)