时间复杂度O(N)
空间复杂度O(1)
动态规划:
> dp[i] = dp[i-1] + p[i] # if i != 0 and dp[i-1] > 0 > dp[i] = p[i] # if i == 0 or dp[i-1] < 0
代码:
class Solution: def FindGreatestSumOfSubArray(self, array): # write code here if not array: return None maxNum = array[0] for i in range(1,len(array)): if array[i-1] > 0: array[i] = array[i-1] + array[i] maxNum = max(maxNum, array[i]) return maxNum