Lonely Number

Imagine a list where almost every number has an exact pair, but one number is left alone. Write a function single_number that returns the element that appears once while every other element appears exactly twice. This kind of check often comes up when searching for missing or extra data.

Примеры

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

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

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

Теги

arraymathhashmap
PostgreSQLv16

Εδώ θα εμφανιστεί το αποτέλεσμα εκτέλεσης του κώδικα

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
[0,0,5]
Expected5
6
Input
[5,0,0]
Expected5
Focus radio
Paused · SomaFM · Fluid