[
bit manipulation
hash table
]
BinarySearch 0447 Lone Integer
Problem statement
https://binarysearch.com/problems/Lone-Integer/
Solution
Equal to Leetcode 0137. Single Number II
Complexity
It is O(n)
for time and O(1)
for space.
Code
class Solution:
def solve(self, nums):
ones, twos = 0, 0
for x in nums:
ones = (ones ^ x) & ~twos
twos = (twos ^ x) & ~ones
return ones