Input: target = 7, nums = [2,3,1,2,4,3]
Output: 2
Explanation: The subarray [4,3] has the minimal length under the problem constraint.
Input: target = 4, nums = [1,4,4]
Output: 1
조건
1 <= target <= 109
1 <= nums.length <= 105
1 <= nums[i] <= 104
class Solution:
def minSubArrayLen(self, target: int, nums: List[int]) -> int:
total, left, right = 0, 0, 0
res = len(nums) + 1
while right < len(nums):
total += nums[right]
while total >= target:
res = min(res, right - left + 1)
total -= nums[left]
left += 1
right += 1
print(total, right, left, res)
if res <= len(nums):
return res
else:
return 0