Open fockspaces opened 6 months ago
The two rules:
so if there's pair numbers in list, we can simply eliminate it by XOR and get the single exist number by initialize the ans as 0.
class Solution: def singleNumber(self, nums: List[int]) -> int: ans = 0 for num in nums: ans ^= num return ans
The two rules:
so if there's pair numbers in list, we can simply eliminate it by XOR and get the single exist number by initialize the ans as 0.