-
Notifications
You must be signed in to change notification settings - Fork 0
2220_MinimumBitFlipstoConvertNumber
a920604a edited this page Apr 14, 2023
·
1 revision
title: 2220. Minimum Bit Flips to Convert Number
tags:
- Bit Manipulation
categories: leetcode
comments: false
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;
}
};
- time complexity
O(n)
- space complexity
O(1)
footer