1. 程式人生 > >LintCode: 最小子陣列

LintCode: 最小子陣列

class Solution:
    """
    @param nums: a list of integers
    @return: A integer denote the sum of minimum subarray
    """
    def minSubArray(self, nums):
        # write your code here
        if not nums:
            return
        n = len(nums)
        dp = [0 for i in range(n)]
        dp[0] = nums[0
] ans = nums[0] for i in range(1, n): dp[i] = min(dp[i-1] + nums[i], nums[i]) ans = min(ans, dp[i]) return ans