- LeetCode 최소 하루에 하나는 풀자는 마인드
- 사용언어: JAVA
190. Reverse Bits
풀이
- 방법: result를 한칸씩 왼쪽으로 쉬프트 하면서 n의 마지막 비트들을 더하기
class Solution {
public int reverseBits(int n) {
int result = 0;
for (int i = 0; i < 32; i++) {
result <<= 1;
result |= (n & 1);
n >>>= 1;
}
return result;
}
}