2917. Find the K-or of an Array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public int findKOr(int[] nums, int k) {
int kor = 0;

for (int i = 0; i < Integer.SIZE - 1; i++) {
int count = 0;
for (int num : nums) {
if ((num & (1 << i)) != 0) {
count++;
}
}
if (count >= k) {
kor += 1 << i;
}
}

return kor;
}
}

References

2917. Find the K-or of an Array