Skip to content

Commit 32f8aa7

Browse files
authored
Create 2220. Minimum Bit Flips to Convert Number (#582)
2 parents ae1dccf + e50dc56 commit 32f8aa7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int minBitFlips(int start, int goal) {
4+
int x = start ^ goal;
5+
int count = 0;
6+
while (x > 0) {
7+
count += x & 1;
8+
x >>= 1;
9+
}
10+
return count;
11+
}
12+
};

0 commit comments

Comments
 (0)