4ms c++ solution a little optimize


  • 0
    L
    class Solution {
    public:
        uint32_t reverseBits(uint32_t n) {
            uint32_t result = 0;
            int i = 32;
    		while(n) {
    		    result <<= 1;
    		    result |= (n&0x01);
    		    n >>= 1;
    		    i--;
    		}
    		result <<= i;
    		return result;
        }
    };

Log in to reply
 

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