Back to February Back to Year 2026
EASY 16 Feb 2026 View on LeetCode

190. Reverse Bits

</> Solution

/**
 * Problem: LeetCode 190 - Reverse Bits
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
public class Solution {
    // you need treat n as an unsigned value
    public int reverseBits(int n) {
        int result = 0;
        for (int i = 0; i < 32; i++) {
            result = (result << 1) | (n & 1);
            n >>>= 1;
        }
        return result;
    }
}

TIME COMPLEXITY

O(1)

SPACE COMPLEXITY

O(1)

TOPICS

Bit Manipulation Divide and Conquer