最大子序和@TOC
def maxSubArray(self, nums: List[int]) -> int:
sum = 0
maxsum = nums[0]
for i in range(len(nums)):
#累加子串
sum += nums[i]
#如果sum比 记录的max字串大,更新max
if sum > maxsum:
maxsum = sum
#如果sum为负,说明该子串到目前为止,和为负数,即最后加的一个数把正向抹平了,sum重置
if sum < 0:
sum = 0
return maxsum