Minimum Size Subarray Sum LeetCode solution in Python
1class Solution:2def minSubArrayLen(self, target, nums):3# Init left pointer and answer4l, ans = 0, len(nums) + 15# Init sum of subarray6s = 07# Iterate through all numbers as right subarray8for r in range(len(nums)):9# Add right number to sum10s += nums[r]11# Check for subarray greater than or equal to target12while s >= target:13# Calculate new min14ans = min(ans, r - l + 1)15# Remove current left nubmer from sum16s -= nums[l]17# Move left index up one18l += 119# No solution20if ans == len(nums) + 1:21return 022# Solution23return ans