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 79627ed commit 5747260Copy full SHA for 5747260
โreverse-bits/mintheon.javaโ
@@ -0,0 +1,24 @@
1
+public class Solution {
2
+ /**
3
+ ์๊ฐ๋ณต์ก๋: O(1) -> ๋ฃจํ๋ ํญ์ 32๋ฒ ๋ฐ๋ณต๋๊ธฐ ๋๋ฌธ
4
+ ๊ณต๊ฐ๋ณต์ก๋: O(1)
5
+ */
6
+
7
+ // you need treat n as an unsigned value
8
+ public int reverseBits(int n) {
9
+ int answer = 0;
10
+ int index = 31;
11
12
+ while(n != 0) {
13
+ // n&1 : ๋ง์ง๋ง ๋นํธ๋ฅผ ์ถ์ถ
14
+ // << : 0์ ํจ๋ฉ์ฒ๋ฆฌ ์์ผ์ ์์ ์๋ฆฌ์๋ก ์ฌ๋ ค๋ฒ๋ฆผ
15
+ answer += (n & 1) << index;
16
17
+ // >>> : ๋ถํธ ์๊ด์์ด ์ค๋ฅธ์ชฝ์ผ๋ก ๋นํธ ์ด๋
18
+ n = n >>> 1;
19
+ index--;
20
+ }
21
22
+ return answer;
23
24
+}
0 commit comments