【数据结构与算法题目集】7-1 最大子列和问题

n = int(input())
nums = list(map(int,input().split()))
def maxSubArray(nums):
    MaxSum = nums[0]
    ThisSum = 0
    for i in range(len(nums)):
        if ThisSum>=0:
            ThisSum = ThisSum + nums[i]
        else:
            ThisSum = nums[i]
        MaxSum = max(ThisSum,MaxSum)
    return MaxSum
print(maxSubArray(nums))

你可能感兴趣的:(#,PTA)