Skip to content

Commit 0c191fe

Browse files
refactor 461
1 parent 7c7e25d commit 0c191fe

File tree

1 file changed

+11
-7
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+11
-7
lines changed

src/main/java/com/fishercoder/solutions/_461.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fishercoder.solutions;
22

33
/**
4+
* 461. Hamming Distance
5+
*
46
* The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
57
68
Given two integers x and y, calculate the Hamming distance.
@@ -22,13 +24,15 @@
2224
The above arrows point to positions where the corresponding bits are different.
2325
*/
2426
public class _461 {
25-
public int hammingDistance(int x, int y) {
26-
int n = x ^ y;
27-
int count = 0;
28-
while (n != 0) {
29-
count++;
30-
n &= (n - 1);
27+
public static class Solution1 {
28+
public int hammingDistance(int x, int y) {
29+
int n = x ^ y;
30+
int count = 0;
31+
while (n != 0) {
32+
count++;
33+
n &= (n - 1);
34+
}
35+
return count;
3136
}
32-
return count;
3337
}
3438
}

0 commit comments

Comments
 (0)