Java Solution; O(1) running time, O(1) memory, 2ms.


  • -1
    S
    public class Solution {
      public int reverseBits(int n) {
        int r = 0;
        for (int i = 31; i >= 0; i--, n >>= 1) {
          r |= ((n & 1) << i);
        }
        return r;
      }
    }
    

Log in to reply
 

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