[LeetCode] Bitwise OR of Even Numbers in an Array

3688. Bitwise OR of Even Numbers in an Array

You are given an integer array nums.

Return the bitwise OR of all even numbers in the array.

If there are no even numbers in nums, return 0.

1
2
3
4
5
6
7
8
class Solution {
public:
int evenNumberBitwiseORs(vector<int>& nums) {
int res = 0;
for(auto& n : nums) if(n % 2 == 0) res |= n;
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/10/11/PS/LeetCode/bitwise-or-of-even-numbers-in-an-array/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.