题意:给定一个无符号32位整数,将其二进制形式左右反置,再以整型返回。

思路:循环32轮,将n往右挤出一位就补到ans的尾巴上。

 class Solution {
public:
uint32_t reverseBits(uint32_t n) {
if( !n ) return ;
uint32_t ans = ;
int i;
for(i=; i<; i++ )
{
ans <<= ;
if( n & )
ans |= ;
n >>=;
}
return ans;
}
};

Reverse Bits

LeetCode Reverse Bits 反置位值的更多相关文章

  1. 2016.5.16——leetcode:Reverse Bits(超详细讲解)

    leetcode:Reverse Bits 本题目收获 移位(<<  >>), 或(|),与(&)计算的妙用 题目: Reverse bits of a given 3 ...

  2. [LeetCode] Reverse Bits 翻转位

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

  3. [leetcode] Reverse Bits

    Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...

  4. leetcode reverse bits python

    Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (re ...

  5. [LeetCode] Reverse Bits 位操作

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

  6. lc面试准备:Reverse Bits

    1 题目 Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represente ...

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

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

  8. LeetCode Reverse Linked List II 反置链表2

    题意:将指定的一段位置[m,n]的链表反置,返回链表头. 思路:主要麻烦在链表头,如果要从链表头就开始,比较特殊. 目前用DFS实现,先找到m-1的位置,再找到n+1的位置,中间这段就是否要反置的,交 ...

  9. LeetCode Reverse Nodes in k-Group 每k个节点为一组,反置链表

    题意:给一个单链表,每k个节点就将这k个节点反置,若节点数不是k的倍数,则后面不够k个的这一小段链表不必反置. 思路:递归法.每次递归就将k个节点反置,将k个之后的链表头递归下去解决.利用原来的函数接 ...

随机推荐

  1. JAVA IO包的整理---------Writer和Reader

    一 Writer public abstract class Writer extends Object implements Appendable, Closeable, Flushable 这个类 ...

  2. adnroid 启动是没有标题栏

    <activity android:name=".MainActivity" android:theme="@android:style/Theme.Light.N ...

  3. .net core 中使用NLog

    在.net standard 2.0.3 和.net core 2.1适用.其他版本的.net 应该也可以. 1.新建一个空白解决方案,再建一个类库 2.安装NLog.Config,会生成一个配置文件 ...

  4. Beta冲刺测试

    1.项目概述 1.项目名称 微信四则运算小程序 2.项目简介 基于微信小程序,为用户提供一个答题的平台 3.项目预期达到目标 用户通过微信小程序可以在里边答题,模式或者题量的选择为用户匹配到适合他们的 ...

  5. win10外接显示器时有些应用和里面的字体显示比较模糊

    打开系统设置 - 选择显示 - 选中外接的显示器 - 点击 "高级缩放设置" 进去后将 "允许 Windows  尝试修改应用,使其不模糊"打开,然后关闭应用再 ...

  6. Mysql-15-mysql分布式应用

    1.分布式应用的概念和优势 分布式数据库是指利用高速网络将物理上分散的多个数据存储单元连接起来组成一个逻辑上统一的数据库.分布式数据库的基本思想是将原来集中式数据库中的数据分散存储到多个通过网络连接的 ...

  7. 动手写一个简单版的谷歌TPU-矩阵乘法和卷积

    谷歌TPU是一个设计良好的矩阵计算加速单元,可以很好的加速神经网络的计算.本系列文章将利用公开的TPU V1相关资料,对其进行一定的简化.推测和修改,来实际编写一个简单版本的谷歌TPU.计划实现到行为 ...

  8. linux_下IP、网关、DNS地址配置

    设置Linux网络的方法有两种: 第一种:修改配置文档(需要重启网络配置,永远生效)一.修改IP地址[aeolus@db1 network-scripts]$ vi ifcfg-eth0DEVICE= ...

  9. 洛谷P2068 统计和

    题目描述 给定一个长度为\(n(n \leq 100000)\),初始值都为\(0\)的序列,\(x(x \leq 10000)\)次的修改某些位置上的数字,每次加上一个数,然后提出\(y (y \l ...

  10. Apache服务器配置虚拟域名

    我在别处发的帖子 http://www.52pojie.cn/thread-599829-1-1.html