题解 | #连续子数组的最大和#
连续子数组的最大和
https://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484
动态规划,遍历时array修改为max(之前连续值加当前值,当前值),拿Max记录最大值即可
class Solution: def FindGreatestSumOfSubArray(self , array: List[int]) -> int: # write code here Max = array[0] for i in range(1,len(array)): array[i] = max(array[i],array[i]+array[i-1]) if array[i]>Max: Max = array[i] return Max