[LeetCode] Reverse Bits 位操作
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as00111001011110000010100101000000).
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.
#include<iostream>
using namespace std; class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t m=;
for(int i=;i<;i++){
m<<=;
m = m|(n & );
n>>=;
}
return m;
}
}; int main()
{
uint32_t n = ;
Solution sol;
cout<<sol.reverseBits(n)<<endl;
return ;
}
[LeetCode] Reverse Bits 位操作的更多相关文章
- 2016.5.16——leetcode:Reverse Bits(超详细讲解)
leetcode:Reverse Bits 本题目收获 移位(<< >>), 或(|),与(&)计算的妙用 题目: Reverse bits of a given 3 ...
- [LeetCode] Reverse Bits 翻转位
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- [leetcode] Reverse Bits
Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...
- leetcode reverse bits python
Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...
- LeetCode Reverse Bits 反置位值
题意:给定一个无符号32位整数,将其二进制形式左右反置,再以整型返回. 思路:循环32轮,将n往右挤出一位就补到ans的尾巴上. class Solution { public: uint32_t r ...
- lc面试准备:Reverse Bits
1 题目 Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represente ...
- [LeetCode] 190. Reverse Bits 颠倒二进制位
Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 ...
- [LeetCode] 190. Reverse Bits 翻转二进制位
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【LeetCode】190. Reverse Bits
题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...
随机推荐
- Ubuntu 下使用虚拟串口进行开发测试
1. python 工具 #coding = utf-8 import pty import os import select def mkpty(): master1, slave = pty.op ...
- tp3.2框架中使用volist输出混乱的一点发现
在tp框架中,volist真的是一样很好用的东西,但是要是不注意,用起来也会有问题的 在Controller层中,将数据assign到页面 $this->assign('vo',$news); ...
- 微信小程序中 this.setData is not a function报错
在微信小程序中我们一般通过以下方式来修改data中的数据: 比如获取小程序缓存: wx.getStorage({ key: 'is_screen', success: function (res) { ...
- php实现的三个常用加密解密功能函数示例
目录 算法一: 算法二: 算法三(改进第一个加密之后的算法) 本文实例讲述了php实现的三个常用加密解密功能函数.分享给大家供大家参考,具体如下: 算法一: //加密函数 function lock_ ...
- Python中的bytes
bytes_lst = [ ('创建bytes',), ('bytes可哈希',), ('编码与解码',), ('常见编码类型',), ('ord() 与 chr()',), ] 创建bytes &g ...
- Xenia and Bit Operations CodeForces - 339D
Xenia and Bit Operations CodeForces - 339D Xenia the beginner programmer has a sequence a, consistin ...
- 【树状数组】CF961E Tufurama
挺巧妙的数据结构题(不过据说这是一种套路? E. Tufurama One day Polycarp decided to rewatch his absolute favourite episode ...
- Codeforces Round #460 (Div. 2)-C. Seat Arrangements
C. Seat Arrangements time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- 【正则】对RegExp执行typeof运算的结果
对RegExp执行typeof运算的结果并不统一,在有些浏览器中返回“function”,在有些中返回“object”. 谷歌: 火狐 IE: **
- laravel5.2总结--请求
1 获取请求 1.1 获取请求的 URI 1>path 方法会返回请求的 URI.所以,如果接收到的请求目标是 http://domain.com/foo/bar,那么 path 方法就 ...