Shortest Subarray with Sum at Least K
Return the length of the shortest, non-empty, contiguous subarray of A
with sum at least K
.
If there is no non-empty subarray with sum at least K
, return -1
.
Example 1:
Example 2:
Example 3:
Note:
1 <= A.length <= 50000
-10 ^ 5 <= A[i] <= 10 ^ 5
1 <= K <= 10 ^ 9
分析
单调递增栈。 找左边比右边小的,左边i比右边j大的无用,
Last updated