Given an array of positive integers nums and a positive integer target, return the minimal length of a
subarray whose sum is greater than or equal to target. If there is no such subarray, return 0 instead.
Example 1:
1 | Input: target = 7, nums = [2,3,1,2,4,3] |
Example 2:
1 | Input: target = 4, nums = [1,4,4] |
Example 3:
1 | Input: target = 11, nums = [1,1,1,1,1,1,1,1] |
Constraints:
1 | 1 <= target <= 109 |
Approach
1 | Use sliding window to find the subarray. |
Algorithm
1 | 1. Add the integers up until the sum is greater than or equal to target. |
Implementation
1 | int minSubArrayLen(int target, int* nums, int numsSize){ |