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 ...
随机推荐
- 激!GSS系列
#include <cstdio> ; ; inline int max(int, int); inline int getint(); inline void putint(int); ...
- [原]php远程odbc连接sqlsvr数据库,自定义端口,命名实例的连接方式
远程odbc连接sqlsvr数据库,自定义端口,命名实例的连接方式,默认如果不修改的话sqlsvr的端口号是1433,默认实例名就是机器名,,如果既用了命名实例,又改了默认端口,改怎么连接数据库呢? ...
- React Native For Android 环境搭建
一. 环境搭建 1. JDK更新 http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html 使用最新的 ...
- 数据绑定时(<%#Eval)单引号双引号嵌套问题
期望得到的HTML如下: onclick='edit("10000001")' 或者 onclick="edit('10000001')" 实际ASP.NET前 ...
- ruby中tes-unitt数据初始化方法整理
在用ruby做测试时,很多时候需要一些数据初始化以及事后的数据恢复还原之类的操作,下面整理了这些方法.require "test/unit" class TestAnion < ...
- OAF_开发系列19_实现OAF对话框提示dialogPage(案例)
20150716 Created By BaoXinjian
- json&pickle&xml
json .dumps() 变成 json 的字符串 import json dic={"name":"alex"} data=json.dumps(di ...
- ACM入门
1.给n个数字,将它们重新排序得到一个最大的数字 例子 4123 124 56 90--------------90561241235123 124 56 90 9------------990561 ...
- Scala的几个小tips
1. Main方法只能写在object而不是class里 2. Unit test只能针对class或者trait,不能给object做,解决方法,把object里面要测的方法拿出来放到trait里, ...
- windows10降低IE版本
win10支持的最低IE版本为IE10,现在IE最新版本为IE11,而win10自带的浏览器是microsoft EDGE ,这给 以前的老系统带来很多不便,为了支持以前的老系统,只有降低IE浏览器 ...