-
Notifications
You must be signed in to change notification settings - Fork 0
LC 0209 [M] Minimum Size Subarray Sum
Code with Senpai edited this page Apr 7, 2022
·
5 revisions
classic sliding window
class Solution:
def minSubArrayLen(self, s: int, nums: List[int]) -> int:
cumsum = 0
min_len = sys.maxsize
l = 0
for r in range(len(nums)):
cumsum += nums[r]
while cumsum >= s:
min_len = min(min_len, r - l + 1)
cumsum -= nums[l]
l += 1
return min_len if min_len != sys.maxsize else 0
footer