We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f08f147 commit acf9053Copy full SHA for acf9053
1 file changed
reverse-bits/sadie100.ts
@@ -0,0 +1,19 @@
1
+/**
2
+ n의 뒤의 자리에서부터 비트로 변환해서 result에 붙이고, result 비트를 앞으로 당기는 일을 32번 반복해서 뒤집어진 비트를 만든다
3
+
4
+ 시간복잡도 : O(1) - 비트 연산
5
+ 공간복잡도 : O(1)
6
+ */
7
8
+function reverseBits(n: number): number {
9
+ let result = 0
10
11
+ for (let i = 0; i < 32; i++) {
12
+ let bit = n & 1
13
14
+ result = (result << 1) | bit
15
16
+ n = n >>> 1
17
+ }
18
+ return result >>> 0
19
+}
0 commit comments