QuestionGiven an integer arraynums, find the subarray with the largest sum, and returnits sum.Example 1:Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
Output: 6
Explanation: The subarray [4,-1,2,1] has the largest sum 6.AlgorithmThe code1 is wrong solution. Code2 is a valid answer. Code1 is mislead by a two pointer solution and tried to solve that way.This question can be solve in a dynamic programming way.For DP, you need to define what is the dp for. Here our dp[i] is until index i, the max sub array for current nums[0, i] array.Then the equation, how we get the next answer from previous results. I t
...
继续阅读
(34)