LintCode: 最小子陣列
阿新 • • 發佈:2019-01-09
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