Skip to content

Commit 330174d

Browse files
refactor 461
1 parent e3bc140 commit 330174d

File tree

1 file changed

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

1 file changed

+11
-34
lines changed
Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,15 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 461. Hamming Distance
5-
*
6-
* The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
7-
8-
Given two integers x and y, calculate the Hamming distance.
9-
10-
Note:
11-
0 ≤ x, y < 231.
12-
13-
Example:
14-
15-
Input: x = 1, y = 4
16-
17-
Output: 2
18-
19-
Explanation:
20-
1 (0 0 0 1)
21-
4 (0 1 0 0)
22-
↑ ↑
23-
24-
The above arrows point to positions where the corresponding bits are different.
25-
*/
263
public class _461 {
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;
36-
}
37-
}
4+
public static class Solution1 {
5+
public int hammingDistance(int x, int y) {
6+
int n = x ^ y;
7+
int count = 0;
8+
while (n != 0) {
9+
count++;
10+
n &= (n - 1);
11+
}
12+
return count;
13+
}
14+
}
3815
}

0 commit comments

Comments
 (0)