Binary Ones Count
Numbers are stored inside computers in binary form, and sometimes you need to know how many 1 bits they contain. Given a non-negative integer n, return the number of 1s in its binary representation. For example, 7 has three set bits in binary. For 0, the answer is 0.
Примеры
Ввод
0Вывод
0Ввод
7Вывод
3Ввод
255Вывод
8Нужно реализовать
def count_set_bits(n):
Теги
mathrecursion
Prihláste sa, aby ste videli históriu odoslaní
Prihlásiť saPrihláste sa, aby ste mohli používať AI mentora
Prihlásiť saVisible tests
1
Input
0Expected
02
Input
7Expected
33
Input
255Expected
84
Input
1024Expected
15
Input
2863311530Expected
166
Input
1Expected
1Focus radio
Paused · SomaFM · Fluid