Skip to content

Commit 0f4f927

Browse files
Merge pull request thepranaygupta#340 from shreya40/patch-9
Create set_bits.java
2 parents 9e3bca1 + 7a3aacd commit 0f4f927

File tree

1 file changed

+15
-0
lines changed
  • Love Babbar DSA Sheet Solutions/Bit Manipulation/Count set bits

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//time: complexity 0(logN)
2+
//Brian Kernighan's Algorithm:
3+
4+
class Solution {
5+
static int setBits(int N) {
6+
int c=0;
7+
while(N!=0)
8+
{
9+
N=N&(N-1);
10+
c++;
11+
}
12+
return c;
13+
14+
}
15+
}

0 commit comments

Comments
 (0)