Created
October 29, 2020 19:51
-
-
Save Ch-sriram/77435395e8b183a28bd2b633243307e6 to your computer and use it in GitHub Desktop.
Bit Difference [TC: O(logN); SC: O(1)]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem Link