Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1567b58

Browse files
authored
Update BrianKernighanAlgorithm.java
1 parent5cf2203 commit1567b58

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

‎Others/BrianKernighanAlgorithm.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
*
99
* algorithm to count the number of set bits in a given number
1010
*
11-
* Subtraction of 1 from a number toggles all the bits (from
12-
* right to left) till the rightmost set bit(including the
11+
* Subtraction of 1 from a number toggles all the bits (from right to left) till the rightmost set bit(including the
1312
* rightmost set bit).
14-
* So if we subtract a number by 1 and do bitwise & with
15-
* itself i.e. (n & (n-1)), we unset the rightmost set bit.
13+
* So if we subtract a number by 1 and do bitwise & with itself i.e. (n & (n-1)), we unset the rightmost set bit.
1614
*
17-
* If we do n & (n-1) in a loop and count the no of times loop
18-
* executes we get the set bit count.
15+
* If we do n & (n-1) in a loop and count the no of times loop executes we get the set bit count.
1916
*
2017
*
2118
* Time Complexity: O(logn)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp