Above is the link to the problem.
Problem
The unsigned decimal integer is given.
Reverse bits of a given 32 bits unsigned integer.
Example
Input: n = 00000010100101000001111010011100
Output: 964176192 (00111001011110000010100101000000)
Explanation: The input binary string 00000010100101000001111010011100(2) = 43261596(10),
so return a decimal integer that is the reverse of the given binary string 964176192(10)
= 00111001011110000010100101000000(2)
Code
Explanation
The unsigned decimal integer is given from the problem.
We change it to a 32bit binary string and reverse it.
When it is less than 32bit long, add 0 to the front of the string until it becomes 32bit long.
Finally, reverse the string and change it to a decimal integer and return it.
This code gets the top 9.81% of time complexity and uses 14MB of memory.
'Code > LeetCode' 카테고리의 다른 글
[LeetCode] 28. Find the Index of the First Occurrence in a String (Medium/Python) (0) | 2023.03.03 |
---|---|
[LeetCode] 191. Number of 1 Bits (Easy/Python) (0) | 2023.03.02 |
[LeetCode] 134. Gas Station (Medium/Python) (0) | 2023.01.14 |
[LeetCode] 1833. Maximum Ice Cream Bars (Medium/Python) (0) | 2023.01.08 |
[LeetCode] 171. Excel Sheet Column Number (Easy/Python) (0) | 2022.11.16 |