#209
#2018.5.5
#https://leetcode.com/problems/minimum-size-subarray-sum/description/
class Solution(object):
def minSubArrayLen(self, s, nums):
if len(nums)==0:
return 0
alls = 0
minlen = len(nums)+1
i = j = 0
while j < len(nums):
while j<len(nums) and alls <s:
alls += nums[j]
j += 1
while i < j and alls >= s:
alls -= nums[i]
i += 1
minlen = min( minlen, j-i+1)
if minlen > len(nums):
minlen = 0
return minlen