题解 | #连续子数组的最大和#
连续子数组的最大和
http://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484
# -*- coding:utf-8 -*-
class Solution:
def FindGreatestSumOfSubArray(self, array):
# write code here
cur = array[0]
ret = cur
for idx, item in enumerate(array):
if idx == 0:
continue
curSum = cur + item
if curSum < item:
cur = item
else:
cur = curSum
if cur > ret:
ret = cur
return ret
class Solution:
def FindGreatestSumOfSubArray(self, array):
# write code here
cur = array[0]
ret = cur
for idx, item in enumerate(array):
if idx == 0:
continue
curSum = cur + item
if curSum < item:
cur = item
else:
cur = curSum
if cur > ret:
ret = cur
return ret