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)/子数组按位或操作 [bitwise-ors-of-subarrays].html
2022-03-29 12:43:11 +08:00

46 lines
1.5 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>我们有一个非负整数数组<meta charset="UTF-8" />&nbsp;<code>arr</code>&nbsp;</p>
<p>对于每个(连续的)子数组<meta charset="UTF-8" />&nbsp;<code>sub = [arr[i], arr[i + 1], ..., arr[j]]</code>&nbsp;&nbsp;<code>i &lt;= j</code>),我们对<meta charset="UTF-8" />&nbsp;<code>sub</code>&nbsp;中的每个元素进行按位或操作,获得结果<meta charset="UTF-8" />&nbsp;<code>arr[i] | arr[i + 1] | ... | arr[j]</code>&nbsp;</p>
<p>返回可能结果的数量。 多次出现的结果在最终答案中仅计算一次。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = [0]
<strong>输出:</strong>1
<strong>解释:</strong>
只有一个可能的结果 0 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = [1,1,2]
<strong>输出:</strong>3
<strong>解释:</strong>
可能的子数组为 [1][1][2][1, 1][1, 2][1, 1, 2]。
产生的结果为 112133 。
有三个唯一值,所以答案是 3 。
</pre>
<p><strong>示例&nbsp;3</strong></p>
<pre>
<strong>输入:</strong>arr = [1,2,4]
<strong>输出:</strong>6
<strong>解释:</strong>
可能的结果是 12346以及 7 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong><meta charset="UTF-8" /></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= nums[i]&nbsp;&lt;= 10<sup>9</sup></code></li>
</ul>