leetcode-Reverse Bits
2015-11-06 22:15
260 查看
Difficulty: Easy
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?
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?
class Solution { public: uint32_t reverseBits(uint32_t n) { int size=sizeof(n)*8; uint32_t res=0; for(int i=0;i<size;++i){ if(n&(1<<i)) res|=(1<<(size-i-1)); } return res; } };
相关文章推荐
- android添加图片到本地,无法即使刷新的解决方法
- Cloud Design Pattern - Compute Resource Consolidation(服务聚合)
- lscpi指令详解
- JAVA微信支付 实现服务端返回预付单号和签名
- 依赖注入
- [hadoop2.7.1]I/O之SequenceFile最新API编程实例(写入、读取)
- 【UI基础】时钟效果的简单实现
- Ubuntu使用教程:E: 无法获得锁 /var/lib/apt/lists/lock - open (11 资源临时不可用)
- iOS 9 适配系列教程
- [C++] const inside class VS const outside class
- 《leetCode》:Valid Parentheses
- 文件管理和归档
- 愤怒的小鸟-物理世界Box2d(3)-刚体碰撞监听
- java开发环境搭建
- 《Linux命令、编辑器与Shell编程》读书笔记4.1-查找和筛选工具(grep,find,sed)
- BDD敏捷开发入门与实战
- BDD敏捷开发入门与实战
- hdu2178 猜数字
- 成长编码5
- textwrap 模块