Format code with prettier (#3375)

This commit is contained in:
acbin
2022-10-03 17:23:00 +08:00
committed by GitHub
parent 32b9b11ed5
commit e96f567bfc
464 changed files with 11483 additions and 6189 deletions

View File

@ -1,6 +1,7 @@
package com.thealgorithms.others;
public class countSetBits {
/**
* The below algorithm is called as Brian Kernighan's algorithm
* We can use Brian Kernighans algorithm to improve the above naive algorithms performance. The idea is to only consider the set bits of an integer by turning off its rightmost set bit (after counting it), so the next iteration of the loop considers the next rightmost bit.
@ -35,12 +36,12 @@ public class countSetBits {
* @param num takes Long number whose number of set bit is to be found
* @return the count of set bits in the binary equivalent
*/
public long countsetBits(long num){
long cnt=0;
while(num>0){
public long countsetBits(long num) {
long cnt = 0;
while (num > 0) {
cnt++;
num&=(num-1);
num &= (num - 1);
}
return cnt;
}
}
}