1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-12 08:55:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (English)/偶数的按位或运算(English) [bitwise-or-of-even-numbers-in-an-array].html
2025-09-25 00:20:19 +08:00

51 lines
1.4 KiB
HTML

<p>You are given an integer array <code>nums</code>.</p>
<p>Return the bitwise <strong>OR</strong> of all <strong>even</strong> numbers in the array.</p>
<p>If there are no even numbers in <code>nums</code>, return 0.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4,5,6]</span></p>
<p><strong>Output:</strong> <span class="example-io">6</span></p>
<p><strong>Explanation:</strong></p>
<p>The even numbers are 2, 4, and 6. Their bitwise OR equals 6.</p>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [7,9,11]</span></p>
<p><strong>Output:</strong> <span class="example-io">0</span></p>
<p><strong>Explanation:</strong></p>
<p>There are no even numbers, so the result is 0.</p>
</div>
<p><strong class="example">Example 3:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,8,16]</span></p>
<p><strong>Output:</strong> <span class="example-io">24</span></p>
<p><strong>Explanation:</strong></p>
<p>The even numbers are 8 and 16. Their bitwise OR equals 24.</p>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 100</code></li>
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
</ul>