|
1 | 1 | [#0862-shortest-subarray-with-sum-at-least-k] |
2 | | -= 862. Shortest Subarray with Sum at Least K |
| 2 | += 862. 和至少为 K 的最短子数组 |
3 | 3 |
|
4 | | -{leetcode}/problems/shortest-subarray-with-sum-at-least-k/[LeetCode - Shortest Subarray with Sum at Least K^] |
| 4 | +https://leetcode.cn/problems/shortest-subarray-with-sum-at-least-k/[LeetCode - 862. 和至少为 K 的最短子数组^] |
5 | 5 |
|
6 | | -Return the *length* of the shortest, non-empty, contiguous subarray of `A` with sum at least `K`. |
| 6 | +给你一个整数数组 `nums` 和一个整数 `k` ,找出 `nums` 中和至少为 `k` 的 *最短非空子数组* ,并返回该子数组的长度。如果不存在这样的 *子数组* ,返回 `-1`。 |
7 | 7 |
|
8 | | -If there is no non-empty subarray with sum at least `K`, return `-1`. |
| 8 | +*子数组* 是数组中 *连续* 的一部分。 |
9 | 9 |
|
10 | | - |
| 10 | +*示例 1:* |
11 | 11 |
|
| 12 | +.... |
| 13 | +输入:nums = [1], k = 1 |
| 14 | +输出:1 |
| 15 | +.... |
12 | 16 |
|
| 17 | +*示例 2:* |
13 | 18 |
|
| 19 | +.... |
| 20 | +输入:nums = [1,2], k = 4 |
| 21 | +输出:-1 |
| 22 | +.... |
14 | 23 |
|
| 24 | +*示例 3:* |
15 | 25 |
|
16 | | -*Example 1:* |
17 | | - |
18 | | -[subs="verbatim,quotes,macros"] |
19 | | ----- |
20 | | -*Input:* A = [1], K = 1 |
21 | | -*Output:* 1 |
22 | | ----- |
23 | | - |
24 | | - |
25 | | -*Example 2:* |
26 | | - |
27 | | -[subs="verbatim,quotes,macros"] |
28 | | ----- |
29 | | -*Input:* A = [1,2], K = 4 |
30 | | -*Output:* -1 |
31 | | ----- |
| 26 | +.... |
| 27 | +输入:nums = [2,-1,2], k = 3 |
| 28 | +输出:3 |
| 29 | +.... |
32 | 30 |
|
| 31 | +*提示:* |
33 | 32 |
|
34 | | -*Example 3:* |
35 | | - |
36 | | -[subs="verbatim,quotes,macros"] |
37 | | ----- |
38 | | -*Input:* A = [2,-1,2], K = 3 |
39 | | -*Output:* 3 |
40 | | ----- |
41 | | - |
42 | | - |
43 | | - |
44 | | -*Note:* |
45 | | - |
46 | | - |
47 | | -. `1 <= A.length <= 50000` |
48 | | -. `-10 ^ 5 <= A[i] <= 10 ^ 5` |
49 | | -. `1 <= K <= 10 ^ 9` |
| 33 | +* `1 \<= nums.length \<= 10^5^` |
| 34 | +* `-10^5^ \<= nums[i] \<= 10^5^` |
| 35 | +* `1 \<= k \<= 10^9^` |
50 | 36 |
|
51 | 37 |
|
52 | 38 |
|
| 39 | +== 思路分析 |
53 | 40 |
|
| 41 | +一脸懵逼! |
54 | 42 |
|
| 43 | +image::images/0862-10.png[{image_attr}] |
55 | 44 |
|
| 45 | +image::images/0862-11.png[{image_attr}] |
56 | 46 |
|
57 | 47 | [[src-0862]] |
| 48 | +[tabs] |
| 49 | +==== |
| 50 | +一刷:: |
| 51 | ++ |
| 52 | +-- |
58 | 53 | [{java_src_attr}] |
59 | 54 | ---- |
60 | 55 | include::{sourcedir}/_0862_ShortestSubarrayWithSumAtLeastK.java[tag=answer] |
61 | 56 | ---- |
| 57 | +-- |
| 58 | +
|
| 59 | +// 二刷:: |
| 60 | +// + |
| 61 | +// -- |
| 62 | +// [{java_src_attr}] |
| 63 | +// ---- |
| 64 | +// include::{sourcedir}/_0862_ShortestSubarrayWithSumAtLeastK_2.java[tag=answer] |
| 65 | +// ---- |
| 66 | +// -- |
| 67 | +==== |
| 68 | + |
| 69 | + |
| 70 | +== 参考资料 |
| 71 | + |
| 72 | +. https://leetcode.cn/problems/shortest-subarray-with-sum-at-least-k/solutions/1925036/liang-zhang-tu-miao-dong-dan-diao-dui-li-9fvh/[862. 和至少为 K 的最短子数组 - 两张图秒懂单调队列^] |
| 73 | +. https://leetcode.cn/problems/shortest-subarray-with-sum-at-least-k/solutions/1923445/he-zhi-shao-wei-k-de-zui-duan-zi-shu-zu-57ffq/[862. 和至少为 K 的最短子数组 - 官方题解^] |
62 | 74 |
|
0 commit comments