答案来自

链接https://blog.nowcoder.net/n/3fc5dfae8c1f44c6b80827d0b96ab8f3?f=comment Python版

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
# [1,-2,3,10,-4,7,2,-5]
# 
# @param array int整型一维数组 
# @return int整型
#
class Solution:
    def FindGreatestSumOfSubArray(self , array: List[int]) -> int:
        # write code here
        max_num= array[0]
        for i in range(1, len(array)):
            if array[i - 1] > 0:
                array[i] = array[i] + array[i-1]
            # else:
               # array[i] = array[i]
            max_num = max(array[i], max_num)
            # print("max_num:", i, "===", max_num)
        # print(array)
        return max_num
    
    # max_num.  1    1    3    13    13    16    18    18
    # array.    1    -1    3    13    9    16    18    13