题解 | #连续子数组的最大和#
连续子数组的最大和
https://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484
from sre_compile import MAX_REPEAT # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param array int整型一维数组 # @return int整型 # import math class Solution: def FindGreatestSumOfSubArray(self , array: List[int]) -> int: # write code here ans = -math.inf / 2 min_pre_sum = pre_sum = 0 for x in array: pre_sum += x ans = max(ans, pre_sum - min_pre_sum) min_pre_sum = min(min_pre_sum, pre_sum) return ans