Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 427 Bytes

README.md

File metadata and controls

28 lines (22 loc) · 427 Bytes

Reverse Bits

Solution 1

/**
 * Question   : Reverse Bits
 * Complexity : Time: O(1) ; Space: O(1)
 * Topics     : Bit
 */
public class Solution {
    public int reverseBits(int n) {
        int output = 0;

        for (int i = 0; i < 32; i++) {
          output <<= 1;

          if ((input & 1) != 0) {
            output |= 1;
          }

          input >>= 1;
        }

        return output;
    }
}