1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-13 01:15:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (English)/颠倒二进制位(English) [reverse-bits].html
2025-09-29 14:43:44 +08:00

68 lines
1.4 KiB
HTML

<p>Reverse bits of a given 32 bits signed integer.</p>
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 43261596</span></p>
<p><strong>Output:</strong> <span class="example-io">964176192</span></p>
<p><strong>Explanation:</strong></p>
<table>
<tbody>
<tr>
<th>Integer</th>
<th>Binary</th>
</tr>
<tr>
<td>43261596</td>
<td>00000010100101000001111010011100</td>
</tr>
<tr>
<td>964176192</td>
<td>00111001011110000010100101000000</td>
</tr>
</tbody>
</table>
</div>
<p><strong class="example">Example 2:</strong></p>
<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 2147483644</span></p>
<p><strong>Output:</strong> <span class="example-io">1073741822</span></p>
<p><strong>Explanation:</strong></p>
<table>
<tbody>
<tr>
<th>Integer</th>
<th>Binary</th>
</tr>
<tr>
<td>2147483644</td>
<td>01111111111111111111111111111100</td>
</tr>
<tr>
<td>1073741822</td>
<td>00111111111111111111111111111110</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 &lt;= n &lt;= 2<sup>31</sup> - 2</code></li>
<li><code>n</code> is even.</li>
</ul>
<p>&nbsp;</p>
<p><strong>Follow up:</strong> If this function is called many times, how would you optimize it?</p>