题目描述:

everse bits of a given 32 bits unsigned integer.

For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as00111001011110000010100101000000).

解题思路:

移位操作。

代码如下:

public class Solution {
// you need treat n as an unsigned value
public int reverseBits(int n) {
int res = 0;
for(int i = 0; i < 32; i++){
res += n & 1;
if(i < 31)
res <<= 1;
n >>>= 1;
}
return res;
}
}

  

Java [Leetcode 190]Reverse Bits的更多相关文章

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

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

  2. Java for 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 颠倒二进制位

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

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

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

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

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

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

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

  7. Leetcode 190 Reverse Bits 位运算

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

  8. 【一天一道Leetcode】#190.Reverse Bits

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 我的个人博客已创建,欢迎大家持续关注! 一天一道le ...

  9. 【LeetCode】190. Reverse Bits 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二进制字符串翻转 位运算 日期 题目地址:https://le ...

随机推荐

  1. Scrum敏捷开发简介

    Agile 敏捷开发实践中,强调团队的自我管理.在 Scrum 中,自我团队管理体现在每天的 Scrum 会议中和日常的协同工作,在每天的 Scrum 例会中,团队成员一般回答一下几个问题 : 昨天完 ...

  2. Winform 窗体的操作

    原文:http://www.cnblogs.com/Billy-rao/archive/2012/05/16/2503437.html 怎样能使winform窗体的大小固定住,不能调整其大小 窗体Fo ...

  3. HDU 1598 find the most comfortable road(枚举+并查集,类似于最小生成树)

    一开始想到用BFS,写了之后,发现有点不太行.网上查了一下别人的解法. 首先将边从小到大排序,然后从最小边开始枚举,每次取比它大的边,直到start.end属于同一个集合,即可以连通时停止.过程类似于 ...

  4. C Primer Plus之C预处理器和C库

    编译程序前,先由预处理器检查程序(因此称为预处理器).根据程序中使用的预处理器指令,预处理器用符号缩略语所代表的内容替换程序中的缩略语. 预处理器不能理解C,它一般是接受一些文件并将其转换成其他文本. ...

  5. Android Drawable 关于selector中state_pressed="true"的位置顺序

    界面中有一个按钮使用这样的样式: <?xml version="1.0" encoding="utf-8"?> <selector xmlns ...

  6. Bash的脚本参数

    $0:脚本名字.此变量包含地址,可以使用basename $0获得脚本名称.$1:第一个参数$2,$3,$4,$5,…一次类推. $# 传递到脚本的参数个数$* 以一个单字符串显示所有向脚本传递的参数 ...

  7. Linux查看随机启动服务

    Liunx操作系统跟Windos XP一样,有一批系统服务随机而启动:略懂电脑的Windows XP用户会禁止那些不必要的服务,以提高开机速度:如今安装了Ubuntu操作系统,咱们也有必要了解Ubun ...

  8. Linux资源监控命令/工具(网络)

    1.手动/自动设定与启动/关闭IP参数:ifconfig,ifup,ifdown      这三个指令的用途都是在启动网络接口,不过,ifup与ifdown仅能就/etc/sysconfig/netw ...

  9. tornado nginx supervisor

    安装:sudo apt-get install python-tornado sudo apt-get install nginx sudo apt-get install supervisor 1. ...

  10. SQLServer中服务器角色和数据库角色权限详解

    角色 当几个用户需要在某个特定的数据库中执行类似的动作时(这里没有相应的Windows用户组),就可以向该数据库中添加一个角色(role).数据库角色指定了可以访问相同数据库对象的一组数据库用户. 数 ...