LeetCode 190 Reverse Bits
来源:互联网 发布:为什么谭咏麟你知我知 编辑:程序博客网 时间:2024/06/05 16:13
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).
Follow up:
If this function is called many times, how would you optimize it?
第一次AC代码:
class Solution {public: uint32_t reverseBits(uint32_t n) { uint32_t ret=0; int length=sizeof(n)*8; for(int i=0,j=length-1;i<length;++i,--j){ ret+=(n&1)*pow(2,j); n=n>>1; } return ret; }};第二次AC代码(参考了大神的代码):
class Solution {public: uint32_t reverseBits(uint32_t n) { int length=sizeof(n)*8; int ret=0; for(int i=0;i<length;++i) ret=(ret<<1)+(n>>i&1); return ret; }};
0 0
- 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
- leetcode 190 Reverse Bits
- LeetCode 190 :Reverse Bits
- 【leetcode 190 Reverse Bits 】
- leetcode 190:Reverse Bits
- Reverse Bits (leetcode 190)
- leetcode[190]:Reverse Bits
- leetcode-190-Reverse Bits
- Apache显示403,Forbidden
- 解读Batch Normalization
- 怎样将Hexo与github page 联系起来
- 14. Longest Common Prefix
- 递归思想
- LeetCode 190 Reverse Bits
- 如何使用PictureBox播放视频
- Evaluate Division
- Java读写Properties
- 数据库基础知识_2
- Qt 连接MySQL 驱动问题
- 类序列化问题-java.io.InvalidClassException
- 1015. Reversible Primes (20)
- 仿微信设置字体大小控件