We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a9ea45d commit 4e6c0acCopy full SHA for 4e6c0ac
July Challenge/HammingDistance.java
@@ -0,0 +1,32 @@
1
+
2
+/**
3
+ * Problem Statement :-
4
+ * https://leetcode.com/explore/challenge/card/july-leetcoding-challenge/544/week-1-july-1st-july-7th/3381/
5
+ *
6
7
+ * Additional Reading:-
8
+ * https://www.techiedelight.com/brian-kernighans-algorithm-count-set-bits-integer/
9
10
11
12
+ */
13
14
+public class HammingDistance {
15
+ public int hammingDistance(int x, int y) {
16
+ int count = 0;
17
18
+ int result = x ^ y;
19
+ while (result > 0) {
20
+ result = (result & result - 1);
21
+ count++;
22
+ }
23
+ return count;
24
25
26
+ public static void main(String[] args) {
27
+ int x = 1;
28
+ int y = 4;
29
+ System.out.println(new HammingDistance().hammingDistance(x, y));
30
31
32
+}
0 commit comments