Loading
Leetcode / 2220. Minimum Bit Flips To Convert Number

Pick a programming language:

Here is the source code for the solution to this problem.

class Solution {
    public int minBitFlips(int start, int goal) {
        int xor = start ^ goal;
        int count = 0;
        while (xor != 0) {
            int digit = xor & 1;
            if (digit == 1) {
                count++;
            }
            xor = xor >> 1;
        }
        return count;
    }
}
Did you like the lesson? 😆👍
Consider a donation to support our work: