2220. Minimum Bit Flips to Convert Number
class Solution {
public int minBitFlips(int start, int goal) {
int count = 0;
while (start > 0 || goal > 0) {
count += (start & 1) ^ (goal & 1);
start >>= 1;
goal >>= 1;
}
return count;
}
}
/**
16 8421
111
1010
*/
Previous1851. Minimum Interval to Include Each QueryNext2419. Longest Subarray With Maximum Bitwise AND
Last updated
Was this helpful?