#209

Minimum Size Subarray Sum

specialist · 850 · lc medium +31 · verified · 51.1% accepted · 14,291 likes · top 40%

play →

Description

Given a positive integer target and an array of positive integers nums, return the minimum length of a contiguous subarray whose sum is at least target. If no such subarray exists, return 0.

Example 1:

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.

Example 2:

Input: target = 4, nums = [1,4,4]
Output: 1

Example 3:

Input: target = 11, nums = [1,1,1,1,1,1,1,1]
Output: 0

Code

1
2
3