class Solution:
"""
@param nums: A list of integers
@return: A integer indicate the sum of max subarray
"""
def maxSubArray(self, nums):
# write your code here
if len(nums) == 0:
return 0
res = nums[0]
tmp = 0
for i in nums:
tmp += i
if tmp < 0:
tmp = 0
continue
if tmp > res:
res = tmp
return res
Python, LintCode, 41. 最大子数组
最新推荐文章于 2022-05-19 19:15:27 发布