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 ...
随机推荐
- Oracle查询表结果添加到另一张表中
转自:https://blog.csdn.net/lx870576109/article/details/78336695 把每一个知识点进行积累:Oracle数据库中将查询一张表的结果添加到另一张表 ...
- 09-清除默认格式 reset.css
根据需要选择和裁剪后使用,以减少代码量 /* 清除内外边距 */ body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, /* structural elem ...
- AS2在FLASH中调用EXE文件方法详细说明 已测试可行
熟悉FLASH功能的朋友都知道fscommand在FLASH中是一个经常用来控制窗口全屏或退出的命令,同时它也是FLASH调用外部可执行程序的一种方法,使用fscommand命令格式如下: fscom ...
- Struts2中使用HttpServletRequest和HttpServletResponse
一.非Ioc方式 这种方式主要是利用了com.opensymphony.xwork2.ActionContext类以及org.apache.struts2.ServletActionContext类, ...
- Block 语法
Block,代码块,^符号是block的语法标记. 比如说,一个block的参数列表是一个UIView,返回值是个CGFloat,block名称是testBlock 可以定义为 CGFloat (^ ...
- BroadcastReceiver的使用,动态注册和注销,优先级和中断控制
BroadcastReceiver: BroadcastReceiver(广播接收器)是Android中的四大组件之一,用来通知某些事件的相关信息,如下载完成,设置改变等. 默认的BroadcastR ...
- php压力测试工具简单实用方法
命令 ab -h 指令帮助 ab -n100 -c10 http://www.baidu.com 发起100个请求 并发数为10 设置测试地址是百度,注意测试测试时候请求数和并发数尽量设置低一点 Re ...
- Haskell语言练习
Monad inc n = Just (n + 1) add1 n = [n + 1] main = do print $ Nothing >> (Just 0) -- Nothing p ...
- IIS8.0 部署WCF Services
今天在Win 8的IIS上部署WCF Services,访问SVC文件时出现找不到处理程序的错误,以前遇到这个问题时都是尝试通过注册asp.net的方式处理一下,但是在Win8下这招不灵了,出现如下提 ...
- GIS案例学习笔记-多边形内部缓冲区地理模型
GIS案例学习笔记-多边形内部缓冲区地理模型 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:对于多边形,建立内部缓冲区. 问题:ArcGIS缓冲工具不支持内部 ...