1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/和至少为 K 的最短子数组 [shortest-subarray-with-sum-at-least-k].html
2022-03-29 12:43:11 +08:00

40 lines
1.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组 <code>nums</code> 和一个整数 <code>k</code> ,找出 <code>nums</code> 中和至少为 <code>k</code><strong>最短非空子数组</strong> ,并返回该子数组的长度。如果不存在这样的 <strong>子数组</strong> ,返回 <code>-1</code></p>
<p><strong>子数组</strong> 是数组中 <strong>连续</strong> 的一部分。</p>
<p>&nbsp;</p>
<ol>
</ol>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1], k = 1
<strong>输出:</strong>1
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2], k = 4
<strong>输出:</strong>-1
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>nums = [2,-1,2], k = 3
<strong>输出:</strong>3
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= k &lt;= 10<sup>9</sup></code></li>
</ul>