190. Reverse Bits

Posted on Mar 22, 2025

Solution

Implementation

class Solution {
    fun reverseBits(n: Int): Int {
        var num = n
        var result = 0
        for (i in 0 until 32) {
            result = (result shl 1) or (num and 1)
            num = num ushr 1
        }
        return result
    }
}