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 471cb9d commit 26b6991Copy full SHA for 26b6991
reverse-bits/gmlwls96.kt
@@ -0,0 +1,14 @@
1
+class Solution {
2
+ // you need treat n as an unsigned value
3
+ fun reverseBits(n: Int): Int {
4
+ var bitString = Integer.toBinaryString(n)
5
+ bitString = CharArray(32 - bitString.length) { '0' }.concatToString() + bitString
6
+ var result = 0
7
+ var scale = 1
8
+ bitString.forEach {
9
+ result += it.digitToInt() * scale
10
+ scale *= 2
11
+ }
12
+ return result
13
14
+}
0 commit comments