File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
3
/**
4
+ * 461. Hamming Distance
5
+ *
4
6
* The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
5
7
6
8
Given two integers x and y, calculate the Hamming distance.
22
24
The above arrows point to positions where the corresponding bits are different.
23
25
*/
24
26
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 ;
31
36
}
32
- return count ;
33
37
}
34
38
}
You can’t perform that action at this time.
0 commit comments