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
Prijavite se za ogled zgodovine oddaj
PrijavaPrijavite se za uporabo mentorja UI
PrijavaVisible tests
1
Input
[2,2,1]Expected
12
Input
[4,1,2,1,2]Expected
43
Input
[1]Expected
14
Input
[7,3,7,3,9]Expected
95
Input
[0,0,5]Expected
56
Input
[5,0,0]Expected
5Focus radio
Paused · SomaFM · Fluid