Last updated
Was this helpful?
Last updated
Was this helpful?
Given an array of n positive integers and a positive integers, find the minimal length of a contiguous subarray 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.
More practice:
If you have figured out theO(n) solution, try coding another solution of which the time complexity isO(nlogn).
两年后再做,调了半天才过。发现right的条件控制有点难度。
个人觉得这题比较像sliding window,首先把有指针移动到符合条件的地方,然后再缩小左指针,缩小时记录结果。
在Lint上的写法更像模板