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

Commite4b6553

Browse files
refactor 191
1 parent0bcda05 commite4b6553

File tree

1 file changed

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

1 file changed

+5
-9
lines changed

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
packagecom.fishercoder.solutions;
22

3-
/**
4-
* 191. Number of 1 Bits
5-
*
6-
* Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).
7-
* For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should return 3.*/
8-
93
publicclass_191 {
104

115
publicstaticclassSolution1 {
12-
/**Doing bitwise AND operation between n and n-1 will always flip the least significant 1 bit in n to zero
13-
example run for the above editorial solution: input 5, n will be 5&4 and becomes 4,
14-
then in the next run, n will become 4&3 which is 0, thus exit the while loop.*/
6+
/**
7+
* Doing bitwise AND operation between n and n-1 will always flip the least significant 1 bit in n to zero
8+
* example run for the above editorial solution: input 5, n will be 5&4 and becomes 4,
9+
* then in the next run, n will become 4&3 which is 0, thus exit the while loop.
10+
*/
1511
publicinthammingWeight(intn) {
1612
intbits =0;
1713
while (n !=0) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp