记得在考研408的辅导书上见过这个算法设计题,非常巧妙,还好没忘,考完研都一年半了,还是蛮怀念西工大的同学们
class Solution(object):
def maxSubArray(self, nums):
maxnum=nums[0]
sum=0
for i in range(len(nums)):
sum=sum+nums[i]
if sum > maxnum:
maxnum=sum
if sum<0:
sum=0
return maxnum