[抄题]:
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
.
方法一:贪心算法greedy
[一句话思路]:
每次都取最大值,sum-max-sum。
[画图]:
[一刷]:
[总结]:
就是背吧。
[复杂度]:
n/1
[英文数据结构]:
[其他解法]:
preflix sum
[题目变变变]:
方法二:preflix sum
[一句话思路]:
[画图]:
[一刷]:
[总结]:
[复杂度]:
[英文数据结构]:
[其他解法]:
[题目变变变]:
时间: 2024-10-14 03:47:15