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
Connectez-vous pour voir l'historique des soumissions
Se connecterConnectez-vous pour utiliser le Mentor IA
Se connecterVisible 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
[]Expected
06
Input
[1,2,2]Expected
1Focus radio
Paused · SomaFM · Fluid