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 40cc64b commit 5d3d672Copy full SHA for 5d3d672
reverse-bits/nhistory.js
@@ -0,0 +1,16 @@
1
+var reverseBits = function (n) {
2
+ // Make variable to store input
3
+ // toString method doesn't include 0 front of number
4
+ let binary = n.toString(2);
5
+
6
+ // Added number of 0s to satisfy 32 bits
7
+ while (binary.length < 32) {
8
+ binary = "0" + binary;
9
+ }
10
11
+ // Reversed binary string and convert into integer
12
+ return parseInt(binary.split("").reverse().join(""), 2);
13
+};
14
15
+// TC: O(1)
16
+// SC: O(1)
0 commit comments