Skip to content

Commit 8f53e13

Browse files
committed
feat(leetcode): 0190 Reverse Bits
1 parent aa2b45c commit 8f53e13

File tree

4 files changed

+48
-60
lines changed

4 files changed

+48
-60
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## [190. Reverse Bits](https://leetcode.com/problems/reverse-bits/)
2+
<p>Reverse bits of a given 32 bits unsigned integer.</p>
3+
4+
<p><strong>Note:</strong></p>
5+
6+
<ul>
7+
<li>Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer&#39;s internal binary representation is the same, whether it is signed or unsigned.</li>
8+
<li>In Java, the compiler represents the signed integers using <a href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank">2&#39;s complement notation</a>. Therefore, in <strong class="example">Example 2</strong> above, the input represents the signed integer <code>-3</code> and the output represents the signed integer <code>-1073741825</code>.</li>
9+
</ul>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> n = 00000010100101000001111010011100
16+
<strong>Output:</strong> 964176192 (00111001011110000010100101000000)
17+
<strong>Explanation: </strong>The input binary string <strong>00000010100101000001111010011100</strong> represents the unsigned integer 43261596, so return 964176192 which its binary representation is <strong>00111001011110000010100101000000</strong>.
18+
</pre>
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
22+
<pre>
23+
<strong>Input:</strong> n = 11111111111111111111111111111101
24+
<strong>Output:</strong> 3221225471 (10111111111111111111111111111111)
25+
<strong>Explanation: </strong>The input binary string <strong>11111111111111111111111111111101</strong> represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is <strong>10111111111111111111111111111111</strong>.
26+
</pre>
27+
28+
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
30+
31+
<ul>
32+
<li>The input must be a <strong>binary string</strong> of length <code>32</code></li>
33+
</ul>
34+
35+
<p>&nbsp;</p>
36+
<p><strong>Follow up:</strong> If this function is called many times, how would you optimize it?</p>

leetcode/0190_reverse_bits/0190_reverse_bits.go renamed to leetcode/0190-reverse-bits/solution.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* Author: 1chooo<hugo970217@gmail.com>
3+
* Problem: https://leetcode.com/problems/reverse-bits/
4+
* Runtime: 0ms (100.00%)
5+
*/
6+
17
package reversebits
28

39
func reverseBits(num uint32) uint32 {

leetcode/0190_reverse_bits/0190_reverse_bits.py renamed to leetcode/0190-reverse-bits/solution.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""
2+
* Author: 1chooo<hugo970217@gmail.com>
3+
* Problem: https://leetcode.com/problems/reverse-bits/
4+
* Runtime: 0ms (100.00%)
5+
"""
6+
17
class Solution:
28
def reverseBits(self, n: int) -> int:
39
result = 0

leetcode/0190_reverse_bits/README.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)