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 76fb734 commit d74dfc1Copy full SHA for d74dfc1
reverse-bits/sunjae95.js
@@ -0,0 +1,18 @@
1
+/**
2
+ * @description
3
+ *
4
+ * n = length of n
5
+ * time complexity: O(n)
6
+ * space complexity: O(n)
7
+ */
8
+var reverseBits = function (n) {
9
+ let answer = 0;
10
+ let binary = n.toString(2);
11
+
12
+ if (binary.length < 32) binary = "0".repeat(32 - binary.length) + binary;
13
14
+ for (let i = binary.length - 1; i >= 0; i--)
15
+ answer += Math.pow(2, i) * Number(binary[i]);
16
17
+ return answer;
18
+};
0 commit comments