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

Commit43a2477

Browse files
refactor 191
1 parentc8ca38e commit43a2477

File tree

1 file changed

+5
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+5
-0
lines changed

‎src/main/java/com/fishercoder/solutions/_191.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ public static class Solution1 {
77
* Doing bitwise AND operation between n and n-1 will always flip the least significant 1 bit in n to zero
88
* example run for the above editorial solution: input 5, n will be 5&4 and becomes 4,
99
* then in the next run, n will become 4&3 which is 0, thus exit the while loop.
10+
*
11+
* e.g. 5 in binary format: 101
12+
* 4 in binary format: 100
13+
* so 5 AND 4 becomes 100, it's the least significant 1-bit in n always maps to a 0-bit in n - 1
14+
* so n ANDs with n - 1, will just set the least significant 1-bit in n to be zero and all other bits remain unchanged
1015
*/
1116
publicinthammingWeight(intn) {
1217
intbits =0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp