[LeetCode] 862. Shortest Subarray with Sum at Least K 和至少为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:

Input: A = [1], K = 1
Output: 1

Example 2:

Input: A = [1,2], K = 4
Output: -1

Example 3:

Input: A = [2,-1,2], K = 3
Output: 3

Note:

  1. 1 <= A.length <= 50000
  2. -10 ^ 5 <= A[i] <= 10 ^ 5
  3. 1 <= K <= 10 ^ 9



Github 同步地址:

https://github.com/grandyang/leetcode/issues/862



参考资料:

https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/



LeetCode All in One 题目讲解汇总(持续更新中...)

猜你喜欢

转载自www.cnblogs.com/grandyang/p/11300071.html
今日推荐