class Solution(object): def maxSubArray(self, nums): """ :type nums: List[int] :rtype: int """ ''' 动态规划,当前状态 只依赖前一个状态,从而进行转移 依赖前一个状态 ('dp', 2, -2) ('dp', 3, 1) ('dp', 4, -2) ('dp', 5, 4) ('dp', 6, 3) ('dp', 7, 5) ('dp', 8, 6) ('dp', 9, 1) ''' lens = len(nums) dp = nums[0] res = nums[0] for i in range(1,lens): print("dp",i+1,dp) dp = max(nums[i] + dp, nums[i]) res = max(res,dp) return res |