Skip to content

Instantly share code, notes, and snippets.

@Ch-sriram
Created October 29, 2020 19:51
Show Gist options
  • Save Ch-sriram/77435395e8b183a28bd2b633243307e6 to your computer and use it in GitHub Desktop.
Save Ch-sriram/77435395e8b183a28bd2b633243307e6 to your computer and use it in GitHub Desktop.
Bit Difference [TC: O(logN); SC: O(1)]
// Problem Link: https://practice.geeksforgeeks.org/problems/bit-difference-1587115620/1/
int countSetBits(int n) {
int count = 0;
while(n) {
++count;
n &= (n-1);
}
return count;
}
int countBitsFlip(int a, int b) {
return countSetBits(a^b);
}
@Ch-sriram
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment