Skip to content

Commit 2596c63

Browse files
authored
Merge pull request #2235 from kimjunyoung90/main
[kimjunyoung90] WEEK 08 solutions
2 parents 295be14 + 2fcbdbb commit 2596c63

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

reverse-bits/kimjunyoung90.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public int reverseBits(int n) {
3+
int result = 0;
4+
5+
for (int i = 0; i < 32; i++) {
6+
//1. result 새 비트 공간 확보
7+
result = result << 1;
8+
9+
//2. n의 마지막 비트 추출
10+
int last = (n & 1);
11+
12+
//3. 마지막 비트 result에 추가
13+
result = result | last;
14+
15+
//4. n 계산한 비트 제거
16+
n = n >> 1;
17+
}
18+
19+
return result;
20+
}
21+
}

0 commit comments

Comments
 (0)