2997. Minimum Number of Operations to Make Array XOR Equal to K
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 85% Topics: Array, Bit Manipulation
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
# bit manipulation
class Solution(object):
def minOperations(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
def popcount(x):
return bin(x).count('1')
return popcount(reduce(lambda x, y: x^y, nums, k))
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions