Find the Unpaired Number

In the list, almost every number appears exactly twice, and only one number has no pair. The function single_number receives a list nums and returns the only number that appears once. This is a good place to use bitwise XOR, because it lets you solve the problem without storing extra data structures.

Примеры

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

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

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

Теги

arraymath
PostgreSQLv16

Itt jelenik meg a kód futtatásának eredménye

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
[]
Expected0
6
Input
[1,2,2]
Expected1
Focus radio
Paused · SomaFM · Fluid