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

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

    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_hashtable([2,2,1])
        1
        >>> single_number_hashtable([4,1,2,1,2])
        4
        >>> single_number_hashtable([1])
        1
        >>> single_number_hashtable([1,1])
        Traceback (most recent call last):
        ...
        ValueError: No element in `nums` appears exactly once.

    """

    """ALGORITHM"""
    ## INITIALIZE VARS ##
    num_counts = {}
    for num in nums:
        num_counts[num] = num_counts.get(num, 0) + 1

    for num, count in num_counts.items():
        if count == 1:
            return num
    else:
        raise ValueError("No element in `nums` appears exactly once.")