209 Minimum Size Subarray Sum
1. Question
Given an array ofnpositive integers and a positive integers, find the minimal length of acontiguoussubarray of which the sum ≥s. If there isn't one, return 0 instead.
For example, given the array[2,3,1,2,4,3]
ands = 7
,
the subarray[4,3]
has the minimal length under the problem constraint.
2. Implementation
(1) Two Pointers
(2) Binary Search
3. Time & Space Complexity
Two Pointers: 时间复杂度O(n), 空间复杂度O(1)
Binary Search: 时间复杂度O(nlogn), 空间复杂度O(1)
Last updated
Was this helpful?