Skip to content

Commit 2d87ed6

Browse files
author
easyone
committed
Feat: Add solution of reverse-bits.
1 parent 89cf4e9 commit 2d87ed6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

reverse-bits/easyone-jwlee.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// 풀이
2+
// result 가장 오른쪽 값에 num의 값을 추가하면서 왼쪽으로 밀어 reverse 처리.
3+
4+
// TC
5+
// for문은 무조건 32회만 돌기때문에 O(1)
6+
7+
// SC
8+
// 추가적인 공간 사용량은 일정하므로 0(1)
9+
10+
func reverseBits(num uint32) uint32 {
11+
result := uint32(0)
12+
for i := 0; i < 32; i++ {
13+
result <<= 1
14+
if num%2 == 1 {
15+
result++
16+
}
17+
num >>= 1
18+
}
19+
return result
20+
}

0 commit comments

Comments
 (0)