Share my 4ms C++ code in O(1) time.


  • 0
    Y
    class Solution {
    public:
    	uint32_t reverseBits(uint32_t n) {
    		uint32_t rst = 0;
    		for (int i = 0; i < 32; ++i) {
    			uint32_t t = n << i;
    			t = t >> 31;
    			t = t << i;
    			rst += t;
    		}
    		return rst;
    	}
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.