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.
2 parents 7e129ba + be01a39 commit 18ed4faCopy full SHA for 18ed4fa
reverse-bits/prograsshopper.java
@@ -0,0 +1,21 @@
1
+class Solution {
2
+ public int reverseBits(int n) {
3
+ int[] stack_n = new int[32];
4
+ int i = 0;
5
+ while(i < 32){
6
+ stack_n[i] = n % 2;
7
+ n /= 2;
8
+ i++;
9
+ }
10
+
11
+ int result = 0;
12
+ int scale = 1;
13
14
+ for(int j=31;j>0;j--){
15
+ result += stack_n[j] * scale;
16
+ scale *= 2;
17
18
19
+ return result;
20
21
+}
reverse-bits/prograsshopper.py
@@ -0,0 +1,15 @@
+class Solution:
+ def reverseBits(self, n: int) -> int:
+ stack_n = []
+ while len(stack_n) < 32:
+ stack_n.append((n % 2))
+ n //= 2
+ result = 0
+ scale = 1
+ while stack_n:
+ result += stack_n.pop() * scale
+ scale *= 2
+ return result
0 commit comments