# Leetcode 53 - Max subarray

`Note`

`DP`

- For each element, there are two situations, one to
`include it`

with prev array, or start with it as a`new array`

. - DP deduction is `dp[i] = max(dp[i-1] + nums[i], nums[i]);
`dp[i]`

represents the largest sum of subarray that`ends with nums[i]`

.- Need a
`result`

to store the result.

- For each element, there are two situations, one to
`Greedy`

- Always pick subs that can make
`count > 0`

, if`count + cur <= 0`

, we need to reset count to 0. - Two var
`count`

, and`result`

to store states.

- Always pick subs that can make

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

A subarray is a contiguous part of an array.

**Example**

1 | Input: nums = [-2,1,-3,4,-1,2,1,-5,4] |

`DP`

1 | /** |

`Greedy`

1 | /** |