2917.找出数组中的K-or值
链接:2917.找出数组中的K-or值
难度:Easy
标签:位运算、数组
简介:返回 nums 的 K-or 值。
题解 1 - python
- 编辑时间:2024-03-06
- 执行用时:89ms
- 内存消耗:16.48MB
- 编程语言:python
- 解法介绍:遍历。
class Solution:
def findKOr(self, nums: List[int], k: int) -> int:
ans = 1-1
for i in range(32):
num = int(len(list(filter(lambda num: (num >> i) & 1, nums))) >= k)
ans |= num << i
return ans