mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-12 17:05:15 +08:00
51 lines
1.4 KiB
HTML
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> </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> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= nums.length <= 100</code></li>
|
|
<li><code>1 <= nums[i] <= 100</code></li>
|
|
</ul>
|