def single_number(nums: list[int]) -> int:
    """Returns the only element in `nums` that appears exactly once

    Better Space than hashtable (O(n/2) = O(n))
        - in the worst case everything appears once before encountering duplicates
        (since we could always delete entries from the hashtable once we encounter exactly 2)

    Complexity:
        n = len(nums)
        Time: O(n)
        Space: O(1)

    Args:
        nums: array of integers s.t. every element appears twice, except for one

    Returns: the only element in `nums` that appears exactly once

    Examples:
        >>> single_number([2,2,1])
        1
        >>> single_number([4,1,2,1,2])
        4
        >>> single_number([1])
        1

    """

    """ALGORITHM"""
    ## INITIALIZE VARS ##
    single_num = 0
    for num in nums:
        single_num ^= num

    return single_num