thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

ByteByteGo: Lonely Integer

β€’ 58 words β€’ 1 min β€’ updated

ByteByteGo: Lonely Integer:

python
from typing import List
from functools import reduce

def lonely_integer(nums: List[int]) -> int:
    return reduce(lambda x, y: x ^ y, nums)

If you forget how to call reduce:

python
from typing import List
from functools import reduce

def lonely_integer(nums: List[int]) -> int:
    ans = 0
    for num in nums:
        ans ^= num
    return ans