class Solution(object):
def maxSubArray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
n = len(nums)
if n == 1:
return nums[0]
ans = pos = nums[0]
for i in range(1, len(nums)):
pos = max(pos + nums[i], nums[i])
ans = max(ans, pos)
return ans
leetcode-53
最新推荐文章于 2021-08-24 16:32:06 发布