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的更多相关文章

  1. [LeetCode] 190. Reverse Bits 颠倒二进制位

    Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 ...

  2. LeetCode 190. Reverse Bits (反转位)

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  3. LeetCode 190. Reverse Bits (算32次即可)

    题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...

  4. [LeetCode] 190. Reverse Bits 翻转二进制位

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  5. Java实现 LeetCode 190 颠倒二进制位

    190. 颠倒二进制位 颠倒给定的 32 位无符号整数的二进制位. 示例 1: 输入: 00000010100101000001111010011100 输出: 0011100101111000001 ...

  6. Leetcode 190 Reverse Bits 位运算

    反转二进制 class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t ans = ; ; i<; ++i,n &g ...

  7. Java for LeetCode 190 Reverse Bits

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  8. Java [Leetcode 190]Reverse Bits

    题目描述: everse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represente ...

  9. Leetcode 190. Reverse Bits(反转比特数)

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

随机推荐

  1. Unity中Instantiate一个prefab时需要注意的问题

    在调用Instantiate()方法使用prefab创建对象时,接收Instantiate()方法返回值的变量类型必须和声明prefab变量的类型一致,否则接收变量的值会为null.   比如说,我在 ...

  2. flask请求管道

    请求管道,登录前的验证,否则重定向到登录页面. # coding: utf8 from flask import render_template, request, g, session, redir ...

  3. linux 添加静态ip dns

    /etc/network 下:interfaces auto loiface lo inet loopbackauto eth0iface eth0 inet staticaddress 192.16 ...

  4. 关于SAP日期操作的几个函数

    1.拆分年月---其实可以直接通过截取字符串的方法得到 CALL FUNCTION 'CACS_DATE_GET_YEAR_MONTH' EXPORTING I_DATE = SY-DATUM IMP ...

  5. laravel/lumen 单元测试

    Testing Introduction Application Testing Interacting With Your Application Testing JSON APIs Session ...

  6. undefined reference to `_init'问题解决

    今天利用CDT 的eclipse调试程序,遇到下面的问题: d:/plugin/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi ...

  7. 【学】AngularJS日记(1) - 常用工具

    angular.isArray(a) 判断a是否为数组 angular.isDate 是否为时间对象 angular.isDefined 判断元素是否存在 angular.isUndefined an ...

  8. iPad开发

    获得view: self.categoryItem.customView 设置控制起 : 在POP ver中的尺寸 self.preferredContentSize = 坚挺三部曲 1. 通过设置 ...

  9. Linux 忘记root密码 的解决办法

    以单用户维护模式登录 先将系统重启, 在读秒时按下任意键进入菜单界面,再仔细看菜单下的说明,按下e就能进入grub的编辑模式,如下 将光标移动到kernel那行, 再次按e进入kernel的编辑界面中 ...

  10. logback

    logback:入口: private final static Logger logger = org.slf4j.LoggerFactory.getLogger(ServiceTest.class ...