Problem 190

Posted by Ruizhi Ma on October 27, 2020

Solution URL

https://leetcode.com/submissions/detail/413909989/

代码

public class Solution {
    // you need treat n as an unsigned value
    public int reverseBits(int n) {
        //ans: https://www.youtube.com/watch?v=OJE5k71dH1U
        int res = 0;
        for(int i = 0; i < 32; i++){
            res = res << 1;
            if((n & 1) == 1) res += 1;
            n = n >> 1;
        }

        return res;
    }
}