Nav: << previous: 189.轮转数组 | next: 191.位1的个数 >>
Description
tab: English
<p>Reverse bits of a given 32 bits signed integer.</p>
<p> </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> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 <= n <= 2<sup>31</sup> - 2</code></li>
<li><code>n</code> is even.</li>
</ul>
<p> </p>
<p><strong>Follow up:</strong> If this function is called many times, how would you optimize it?</p>
---
[submissions](https://leetcode.com/problems/reverse-bits/submissions/) | [solutions](https://leetcode.com/problems/reverse-bits/solutions/)
tab: 中文
<p>颠倒给定的 32 位有符号整数的二进制位。</p>
<p> </p>
<p><strong class="example">示例 1:</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>n = 43261596</span></p>
<p><span class="example-io"><b>输出:</b>964176192</span></p>
<p><strong>解释:</strong></p>
<table>
<tbody>
<tr>
<th>整数</th>
<th>二进制</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">示例 2:</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>n = 2147483644</span></p>
<p><span class="example-io"><b>输出:</b>1073741822</span></p>
<p><strong>解释:</strong></p>
<table>
<tbody>
<tr>
<th>整数</th>
<th>二进制</th>
</tr>
<tr>
<td>2147483644</td>
<td>01111111111111111111111111111100</td>
</tr>
<tr>
<td>1073741822</td>
<td>00111111111111111111111111111110</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 <= n <= 2<sup>31</sup> - 2</code></li>
<li><code>n</code> 为偶数</li>
</ul>
<p> </p>
<p><strong>进阶</strong>: 如果多次调用这个函数,你将如何优化你的算法?</p>
---
[提交记录](https://leetcode.cn/problems/reverse-bits/submissions/) | [题解](https://leetcode.cn/problems/reverse-bits/solution/)
Solutions & Notes
properties:
note.updated:
displayName: Last Updated
note.relative_links:
displayName: Related Links
note.desc:
displayName: Description
note.grade:
displayName: Rating
note.program_language:
displayName: Language
note.time_complexity:
displayName: TC
note.space_complexity:
displayName: SC
views:
- type: table
name: Solutions & Notes
filters:
and:
- file.hasLink(this.file)
- file.tags.containsAny("leetcode/solution", "leetcode/note")
order:
- file.name
- desc
- program_language
- time_complexity
- space_complexity
- grade
- relative_links
- updated
sort:
- property: grade
direction: ASC
- property: time_complexity
direction: ASC
- property: program_language
direction: ASC
columnSize:
file.name: 104
note.space_complexity: 65
note.grade: 126
Similar Problems
properties:
note.lcTopics:
displayName: Topics
note.lcAcRate:
displayName: AC Rate
note.favorites:
displayName: Favorites
note.grade:
displayName: Rating
note.translatedTitle:
displayName: Title (CN)
note.lcDifficulty:
displayName: Difficulty
views:
- type: table
name: Similar Problems
filters:
and:
- file.hasLink(this.file)
- similarQuestions.contains(this.file)
order:
- file.name
- translatedTitle
- lcTopics
- lcDifficulty
- lcAcRate
- grade
- favorites
sort:
- property: file.name
direction: ASC
- property: lcTopics
direction: DESC
columnSize:
note.translatedTitle: 240
note.lcTopics: 347
note.lcAcRate: 75
note.grade: 122