题解 | #连续子数组的最大和#
连续子数组的最大和
https://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param array int整型一维数组
# @return int整型
#
class Solution:
def FindGreatestSumOfSubArray(self, array: List[int]) -> int:
# write code here
dp = [0] * len(array)
dp[0] = array[0]
for i in range(1, len(array)):
if array[i] + dp[i - 1] > array[i]:
dp[i] = array[i] + dp[i - 1]
else:
dp[i] = array[i]
return max(dp)