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 的最短子数组 I [shortest-subarray-with-or-at-least-k-i].html
2024-04-07 13:02:43 +08:00

54 lines
2.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>给你一个 <strong>非负</strong>&nbsp;整数数组&nbsp;<code>nums</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;</p>
<p>如果一个数组中所有元素的按位或运算 <code>OR</code>&nbsp;的值 <strong>至少</strong>&nbsp;<code>k</code>&nbsp;,那么我们称这个数组是 <strong>特别的</strong>&nbsp;</p>
<p>请你返回&nbsp;<code>nums</code>&nbsp;&nbsp;<strong>最短特别非空</strong>&nbsp;<span data-keyword="subarray-nonempty">子数组</span>的长度,如果特别子数组不存在,那么返回 <code>-1</code>&nbsp;</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,3], k = 2</span></p>
<p><span class="example-io"><b>输出:</b>1</span></p>
<p><strong>解释:</strong></p>
<p>子数组&nbsp;<code>[3]</code>&nbsp;的按位&nbsp;<code>OR</code> 值为&nbsp;<code>3</code>&nbsp;,所以我们返回 <code>1</code>&nbsp;</p>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [2,1,8], k = 10</span></p>
<p><span class="example-io"><b>输出:</b>3</span></p>
<p><strong>解释:</strong></p>
<p>子数组&nbsp;<code>[2,1,8]</code> 的按位&nbsp;<code>OR</code>&nbsp;值为 <code>11</code>&nbsp;,所以我们返回 <code>3</code>&nbsp;</p>
</div>
<p><strong class="example">示例 3</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2], k = 0</span></p>
<p><span class="example-io"><b>输出:</b>1</span></p>
<p><b>解释:</b></p>
<p>子数组&nbsp;<code>[1]</code>&nbsp;的按位&nbsp;<code>OR</code>&nbsp;值为&nbsp;<code>1</code>&nbsp;,所以我们返回&nbsp;<code>1</code>&nbsp;</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 50</code></li>
<li><code>0 &lt;= nums[i] &lt;= 50</code></li>
<li><code>0 &lt;= k &lt; 64</code></li>
</ul>