[勇者闯LeetCode] 190. Reverse Bits
来源:互联网 发布:apache listen 编辑:程序博客网 时间:2024/05/17 05:12
[勇者闯LeetCode] 190. Reverse Bits
Description
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000).
Information
- Tags: Bit Manipulation
- Difficulty: Easy
Solution
result
初值为0
,32次循环:
每次result
先左移一位,然后将n
与1进行&
操作取出n
的最后一位,通过|
操作放到result
的最后一位上,n
右移一位。
C++ Code
class Solution {public: uint32_t reverseBits(uint32_t n) { uint32_t result = 0; int count = 32; while (count--) { result <<= 1; result |= n & 1; n >>= 1; } return result; }};
阅读全文
0 0
- [勇者闯LeetCode] 190. Reverse Bits
- [勇者闯LeetCode] 7. Reverse Integer
- [勇者闯LeetCode] 191. Number of 1 Bits
- 【LeetCode】190.Reverse bits
- LeetCode 190. Reverse Bits
- Leetcode 190. Reverse Bits
- 190. Reverse Bits LeetCode
- LeetCode *** 190. Reverse Bits
- LeetCode 190. Reverse Bits
- Leetcode-190. Reverse Bits
- Leetcode 190. Reverse Bits
- LeetCode-190.Reverse Bits
- [leetcode] 190. Reverse Bits
- Leetcode 190. Reverse Bits
- [Leetcode]190. Reverse Bits
- LeetCode 190. Reverse Bits
- [leetcode] 190. Reverse Bits
- leetcode 190. Reverse Bits
- mnist测试
- POJ 3160 Father Christmas flymouse
- 56、57、58
- 显示人物信息
- **ANDROID** 事件处理
- [勇者闯LeetCode] 190. Reverse Bits
- hackerrank>Dashboard>C++>STL>Lower Bound-STL
- CCF 给出最大的数
- 【知识库】--spring --bean的加载简介(226)
- git学习
- **ANDROID** activity和Fragment
- 给lua文件注入插件的方法
- Mysql学习:易忘知识点
- 个人爱好选择