Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥s. If there isn't one, return 0 instead.
For example, given the array[2,3,1,2,4,3]ands = 7,
the subarray[4,3]has the minimal length under the problem constraint.
class Solution(object):
def minSubArrayLen(self, s, nums):
"""
:type s: int
:type nums: List[int]
:rtype: int
"""
size = len(nums)
start, end, sum = 0, 0, 0
bestAns = size + 1
while end < size:
while end < size and sum < s:
sum += nums[end]
end += 1
while start < end and sum >= s:
bestAns = min(bestAns, end - start)
sum -= nums[start]
start += 1
return [0, bestAns][bestAns <= size]