###### Authentic Preference

Technologies come and technologies go, but insight is forever.

### 原题

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.

For example, given the array [-2,1,-3,4,-1,2,1,-5,4],
the contiguous subarray [4,-1,2,1] has the largest sum = 6.

### 题目分析

MaxSubArray(int[] nums, int i, int j)

dyna[i] = nums[i] + (dyna[i-1]>0 ? dyna[i-1]:0)
max = Max(max, dyna[i])

### 代码实现

        public int MaxSubArray(int[] nums)
{
int n = nums.Length;
int[] dyna = new int[n];
dyna[0] = nums[0];
int max = dyna[0];

for (int i = 1; i < n; i++)
{
dyna[i] = nums[i] + (dyna[i - 1] > 0 ? dyna[i - 1] : 0);
max = Math.Max(dyna[i], max);
}

return max;
}

#### SpriteKit Programming Guide手游开发之(FAKE STICK HERO)

2015年03月23日 16:44

#### LeetCode-53-Maximum Subarray(DP/分治)-Medium

2016-01-16 21:07:20

#### 53. Maximum Subarray-动态规划/分治

2016-09-04 17:30:45

#### 【leetcode】【53】Maximum Subarray

2016-03-01 11:21:30

#### LeetCode 53. Maximum Subarray（最大子数组）

2016-05-21 06:53:56

#### LeetCode53. Maximum Subarray 动态规划和分治法

2016-09-20 23:26:36

#### LeetCode(53)Maximum Subarray

2014-01-29 11:00:36

#### 54.Maximum Subarray（动态规划）

2016-01-09 23:02:38

#### [C++]LeetCode: 58 Maximum Subarray

2014-12-28 12:05:38

#### LeetCode--No.53--Maximum Subarray

2016-06-04 04:03:50

## 不良信息举报

LeetCode-Easy部分中标签为 Dynamic Programming(DP) 53. Maximum Subarray