#coding=utf-8
# 解题思路:滑动窗口 (本质上是搜索剪支) 20190302 找工作期间
class Solution(object):
def minSubArrayLen(self, s, nums):
"""
:type s: int
:type nums: List[int]
:rtype: int
"""
l = 0
r = -1
sum = 0
res = len(nums)+1
while(l < len(nums)):
if r+1 < len(nums) and sum < s :
sum += nums[r+1]
r += 1
else:
if r+1 == len(nums) and sum <s :
sum -= nums[l]
l += 1
if r+1 == len(nums) and sum >= s:
res = min(res,r-l+1)
sum -= nums[l]
l += 1
if r+1 < len(nums) and sum >= s:
res = min(res, r - l + 1)
sum -= nums[l]
l += 1
if res == len(nums)+1:
return 0
else :
return res
t = 7
nums = [2,3,1,2,4,3]
s = Solution()
print s.minSubArrayLen(7,nums)