一、leetcode地址
https://leetcode.com/problems/maximum-subarray/
二、问题描述
三、代码实现
语言:Python3
代码:
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
temp = nums[0];total = nums[0]
for i in range(1,len(nums)):
if temp + nums[i] > nums[i]:
temp += nums[i]
else:
temp = nums[i]
if temp > total:
total = temp
return total