190. Reverse Bits
2016-07-08 23:27
246 查看
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?
Related problem:
Reverse Integer
Credits:
Special thanks to
@ts for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
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?
Related problem:
Reverse Integer
Credits:
Special thanks to
@ts for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
class Solution { public: uint32_t reverseBits(uint32_t n) { bitset<32> b1; int i=32; while(i>0) { b1[i-1]=n&1; n=n>>1; i--; } return b1.to_ulong(); } };
相关文章推荐
- linux一行命令查找进程并杀掉进程
- hdu 2437 Jerboas 最短路
- DAG图与拓扑排序 (士兵排队问题)
- 有能愉快的敲代码了
- IE 11 请求语言zh-Hans-CN所引发的问题及解决方案
- 吐槽2个合作公司
- 资治通鉴导读笔记
- [置顶] linux开发php c扩展实例
- Android中定义接口的用法
- GCC定义和应用
- 如何提高用户体验
- 203. Remove Linked List Elements
- 嵌入式入门知识
- Why would you learn C++ in 2016?(2016年,为什么我们要学习C++)
- Why would you learn C++ in 2016?(2016年,为什么我们要学习C++)
- Masory框架
- Two Sum
- LeetCode 072 Edit Distance
- 模仿UIApplication单例实现方式
- Codefroces 675 B. Restoring Painting