Skip to content

Commit e4f8a39

Browse files
committed
Runtime 0 ms (Top 100.0%) | Memory 39.0 MB (Top 63.88%)
1 parent f8596f5 commit e4f8a39

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
// Runtime: 1 ms (Top 81.71%) | Memory: 41.5 MB (Top 17.69%)
21
class Solution {
3-
public int minBitFlips(int start, int goal) {
4-
int xor =start ^ goal;
5-
int count=0;
6-
while(xor>0){
7-
count++;
8-
xor=xor & (xor-1);
9-
}
10-
return count;
11-
12-
}
2+
public static int minBitFlips(int a1, int a2) {
3+
int n = (a1 ^ a2);
4+
int res = 0;
5+
while (n != 0) {
6+
res++;
7+
n &= (n - 1);
8+
}
9+
return res;
10+
}
1311
}

0 commit comments

Comments
 (0)