Unpaired Value

In this list, almost every number appears as a pair, but one value has no matching copy. Given nums, return that single element. The solution must run in O(n) time and use O(1) extra space. Think about the xor operation, where equal numbers cancel each other out.

Примеры

Ввод
[2, 2, 1]
Вывод
1
Ввод
[4, 1, 2, 1, 2]
Вывод
4
Ввод
[1]
Вывод
1

Нужно реализовать

def single_number(nums: list[int]) -> int:

Теги

matharrayhashmap
PostgreSQLv16

Your code output will appear here

Visible tests
1
Input
[2,2,1]
Expected1
2
Input
[4,1,2,1,2]
Expected4
3
Input
[1]
Expected1
4
Input
[7,3,7,3,9]
Expected9
5
Input
[-1,-1,5]
Expected5
6
Input
[7,3]
Expected4
Focus radio
Paused · SomaFM · Fluid