c++ solution (3ms)


  • 0
    class Solution {
    public:
      uint32_t reverseBits(uint32_t n) {
        uint32_t ans = 0, mx = INT_MAX + 1;
        while (n) {
          ans += (n & 1) * mx;
          n >>= 1;
          mx >>= 1;
        }
        return ans;
      }
    };
    

Log in to reply
 

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