Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 579 Bytes

190. Reverse Bits.md

File metadata and controls

35 lines (27 loc) · 579 Bytes

Leetcode

190. Reverse Bits

문제링크

코드

class Solution {
    func reverseBits(_ n: Int) -> Int {
        print(String(n, radix: 2))
        var ret: Int = 0
        var cnt: Int = 0
        for bit in String(n, radix:2).reversed() {
            if bit == "0" {
                ret = ret << 1
            } else {
                ret = ret << 1 + 1
            }
            cnt += 1
        }
        ret = ret << (32 - cnt)
        return ret
    }
}

풀이 이유

참고한 내용