2220_MinimumBitFlipstoConvertNumber - a920604a/leetcode GitHub Wiki
- Bit Manipulation
categories: leetcode
comments: false
title: 2220. Minimum Bit Flips to Convert Number
tags:problem
solution
class Solution {
public:
int minBitFlips(int start, int goal) {
int n = start^goal, count = 0;
// count one
while(n){
n &=(n-1);
count++;
}
return count;
}
};
analysis
- time complexity
O(n)
- space complexity
O(1)