Python, LintCode, 41. 最大子数组

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

猜你喜欢

转载自blog.csdn.net/u010342040/article/details/80288618