+ 3
[challenge]Find number of set bits in a number with in an iteration?
must find in one iteration
11 Answers
+ 2
Here is the oneliner fast solution
https://code.sololearn.com/ckyITt17dCeJ/?ref=app
+ 4
Do you define "set bits" as bits = 1, so that
7 --> 0111 ie 3 set bits.
if so
in python
num=7
print(len(''.join(str(bin(num))[2:].split('0'))))
+ 3
create a table then lookup in the table : gives you the bit set in one operation
+ 2
you can do it, but I'm not familiar with java
+ 2
there we go
https://code.sololearn.com/cFqXLYbAS1nK/?ref=app
+ 2
@Amal Poulose
Corrected the code and now it works fine.
+ 1
you have to find it in single iteration means no loops
+ 1
is java allowed?
+ 1
@kinshuk vasisht check your code with upper limit of long long int