leetcode python 53. 最大子序和

https://leetcode-cn.com/problems/maximum-subarray/description/
杭电oj上的第二题?
好像可以用分治也可以解,我还是用扫一遍的方法水过了,可以看下别人的分治解法

class Solution:
    def maxSubArray(self, nums):
        sum = 0
        Max = nums[0]
        for s in nums:
            if sum + s >= 0:
                sum = sum + s
                if sum > Max:
                    Max = sum
            else:
                sum = 0
                if s > Max:
                    Max = s
        return Max

你可能感兴趣的:(Leetcode)