File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ from unittest import TestCase , main
2+
3+
4+ class Solution :
5+ def reverseBits (self , n : int ) -> int :
6+ return self .solve (n )
7+
8+ """
9+ Runtime: 32 ms (Beats 80.50%)
10+ Time Complexity: O(1)
11+ - n์ str๋ก ๋ณํํ๋๋ฐ, n์ 32 bit ์ ์์ด๋ฏ๋ก O(32), upper bound
12+ - zfill๋ก ๋ฌธ์์ด์ ๊ธธ์ด๋ฅผ 32๋ก ๋ง์ถ๋๋ฐ, O(32), upper bound
13+ - ๋ฌธ์์ด์ ๋ค์ง๋๋ฐ ๋ง์ฐฌ๊ฐ์ง๋ก, O(32), upper bound
14+ - ๋ค์ง์ ๋ฌธ์์ด์ ์ ์๋ก ๋ณํํ๋๋ฐ ๋ฌธ์์ด์ ๋น๋กํ๋ฉฐ ์ด ๊ธธ์ด๋ ์ต๋ 32์ด๋ฏ๋ก, O(32), upper bound
15+ > O(32) * O(32) * O(32) * O(32) ~= O(1)
16+
17+ Memory: 16.50 (Beats 64.72%)
18+ Space Complexity: O(1)
19+ - ๊ฐ ๋จ๊ณ๋ง๋ค ์ต๋ ๊ธธ์ด๊ฐ 32์ธ ๋ฌธ์์ด์ด ์์๋ก ์ ์ฅ๋๋ฏ๋ก O(32) * 4
20+ > O(32) * 4 ~= O(1)
21+ """
22+ def solve (self , n : int ) -> int :
23+ return int (str (n ).zfill (32 )[::- 1 ], 2 )
24+
25+
26+ class _LeetCodeTestCases (TestCase ):
27+ def test_1 (self ):
28+ n = int ("00000010100101000001111010011100" )
29+ output = 964176192
30+ self .assertEqual (Solution .reverseBits (Solution (), n ), output )
31+
32+
33+ if __name__ == '__main__' :
34+ main ()
You canโt perform that action at this time.
0 commit comments