You are viewing a single comment's thread. Return to all comments →
Here is my c++ solution, you can watch the video explanation here : https://youtu.be/eZ0lTIzOjhQ
V1
long flippingBits(long n) { long result = 0; for(int i = 31; i >= 0; i--) { if(n >= pow(2, i)){ n -= pow(2,i); } else result += pow(2, i); } return result; }
V2
long flippingBits(long n) { return 4294967295 ^ n; }
Seems like cookies are disabled on this browser, please enable them to open this website
Flipping bits
You are viewing a single comment's thread. Return to all comments →
Here is my c++ solution, you can watch the video explanation here : https://youtu.be/eZ0lTIzOjhQ
V1
V2