leetcode 190
190. 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 as 00111001011110000010100101000000).
Follow up:
If this function is called many times, how would you optimize it?
Related problem: Reverse Integer
按位翻转输入的整数。
代码如下:
class Solution {
public:
uint32_t reverseBits(uint32_t n) {
unsigned ret = ;
unsigned pos1 = << ;
unsigned pos2 = ;
while(pos1)
{
if(pos1 & n)
ret |= pos2;
pos2 <<= ;
pos1 >>= ;
}
return ret;
}
};
leetcode 190的更多相关文章
- [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 (算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. For example, given input 43261596 (represented in ...
- Java实现 LeetCode 190 颠倒二进制位
190. 颠倒二进制位 颠倒给定的 32 位无符号整数的二进制位. 示例 1: 输入: 00000010100101000001111010011100 输出: 0011100101111000001 ...
- Leetcode 190 Reverse Bits 位运算
反转二进制 class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t ans = ; ; i<; ++i,n &g ...
- Java for LeetCode 190 Reverse Bits
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- Java [Leetcode 190]Reverse Bits
题目描述: everse 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. For example, given input 43261596 (represented in ...
随机推荐
- 数据库备份Sql
今天学习心得: 数据库备份语句: backup database ZhiHuiGongDi To disk = 'D:\zhihuigongdi20150824.bak'
- C#四种深拷贝方法
//四种深拷贝方法 public static T DeepCopyByReflect<T>(T obj) { //如果是字符串或值类型则直接返回 if (obj is string || ...
- webbrowser 禁用 alert
void web_Navigated(object sender, WebBrowserNavigatedEventArgs e) { var web = sender as System.Windo ...
- Android应用开发-数据存储和界面展现(二)(重制版)
SQLite数据库 // 自定义类MyOpenHelper继承自SQLiteOpenHelper MyOpenHelper oh = new MyOpenHelper(getContext(), &q ...
- 基于Lattice_CPLD/FPGA Diamond 开发流程
本文主要介绍了Lattice CPLD/FPGA集成开发环境的使用方法,并通过点亮开发板(Mach XO2 Breakout Board)上位号为D2的LED这一实例来演示其开发流程. 1. ...
- IOS开发之application/x-www-form-urlencoded ;charset=utf-8
本来常用的是application/json的这中格式,做ios常用的网络请求框架AFNetworking,默认也是application/json,前不久就遇到这种接受格式问题,按照网上各种说法,改 ...
- 通过Daffodil for VS使VS2010的IDE可以用VC6 VC7.1 VC9等编译器进行项目编译
本文内容中的部分资料和知识来源于网络,具体引用出处不明. VS的IDE从VC6到VS2010的变化可谓是天翻地覆,最新的VS2010有一个特性就是支持多显示器开发,这无疑为我们的开发带来很大的便利. ...
- 黄聪:css3实现图片划过一束光闪过效果(图片光影掠过效果)
CSS代码 .guangshu { display:block; position: relative; width:800px; height:450px; margin:0 auto;} .gua ...
- 建立一套完整的Maven依赖工程步骤,包含WEB工程
建立Java Web工程:File -> New -> other… -> Web -> Dynamic Web Project,abs-inf选中该工程右键 -> co ...
- Sublime Text 2/3安装使用及常用插件
一.介绍 Sublime Text 是一款较新的编辑器,它轻量.简洁.高效,良好的扩展性以及跨平台等特性,使得越来越多的开发人员喜爱.它是一款收费的商业软件,但可以免费无限制无限期的试用,只会偶尔提醒 ...