190. Reverse Bits (Int; Bit)
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) {
uint32_t ret = ; //NOTE: integer got from this way should be decalred as unsigned
int tmp;
/*把一个unsigned int 数字1一直左移,直到它变成全0的时候,也就得到了该机器内unsigned int的长度*/
for (i = ; i != ; i <<= )
tmp = n & 0x1;
n >>= ;
ret <<= ; //must before the operation |
ret |= tmp;
}
return ret;
}
};
190. Reverse Bits (Int; Bit)的更多相关文章
- LeetCode 190. Reverse Bits (算32次即可)
题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...
- [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 ...
- Java for LeetCode 190 Reverse Bits
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 190. Reverse Bits -- 按位反转
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 190. Reverse Bits
题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...
- 【LeetCode】190. Reverse Bits
题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...
- LeetCode 190. Reverse Bits (反转位)
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【一天一道Leetcode】#190.Reverse Bits
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 我的个人博客已创建,欢迎大家持续关注! 一天一道le ...
随机推荐
- 网站优化--减少HTTP请求
发送HTTP请求需要经过几个过程 域名解析--TCP连接--发送请求--等待--下载资源--解析时间 这其中需要花费一定时间,因此,尽可能的需要减少网站的HTTP请求,方法有以下几种: 1 . css ...
- Vue.js——60分钟组件快速入门(下篇)
转自:https://www.cnblogs.com/keepfool/p/5637834.html 概述 上一篇我们重点介绍了组件的创建.注册和使用,熟练这几个步骤将有助于深入组件的开发.另外,在子 ...
- 网站优化JS css压缩
在nginx 中开启gzip压缩后,可以大大减少资js css 体积,原来200KB,压缩后只有66KB server{ gzip on; gzip_types text/plain applicat ...
- Netbeans使用技巧
Html代码中的图片.JS.CSS等的引用,不再需要手动输入,非常好用! 直接将你要引用的文件用鼠标拖拽到当中.即使图片.JS.CSS与自己的Html不在同一目录下,Netbeans也会自动为你添加引 ...
- How to start a VirtualBox VM headless in Windows 10
If you wanted to start a VirtualBox VM headless (no UI) in the past, you needed additional tools. I ...
- 在windows、linux中开启nginx的Gzip压缩大大提高页面、图片加载速度<转>
为了降低tomcat服务的压力,把页面上的图片采用windows版的nginx进行加载,由于有些图片比较大,加载特别的慢,所以在nginx中打开了gzip的压缩功能.加载图片的速度快了很多. 通过站长 ...
- 04_JSX练习
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- MethodInfo类的一般使用
1.MethodInfo类是在System.Reflection命名空间底下,既然是在Reflection空间底下.故名思议关于反射相关的操作,其中比较重要的方法是Invoke()方法,它 是加载相同 ...
- css3 之border-radius 属性解析
在css 设置样式的时候,有时候会用到将元素的边框设置为圆形的样子的时候,一般都是通常直接设置:{border-radius:5px },这样就行了,但是到底是什么意思,一直以来都没有弄明白,只是知道 ...
- pbft流程深层分析和解释(转)
<1>pbft五阶段请求解释 Request pre-prepare prepare commit 执行并reply (1)pre-prepare阶段: 主节点收到客户端请求, ...