题意:给定一个无符号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. 交叉编译Spice-gtk

    Fedora环境 编译环境 操作系统: 64位 Fedora23 下载源文件 spice-gtk.spice-protocol 安装依赖 $ sudo yum install -y dh-autore ...

  2. All Roads Lead to Rome(30)(MAP【int,string】,邻接表,DFS,模拟,SPFA)(PAT甲级)

    #include<bits/stdc++.h>using namespace std;map<string,int>city;map<int,string>rcit ...

  3. Codeforces Round #507 (Div. 2)C(贪心,逆向遍历,构造)

    #include<bits/stdc++.h>using namespace std;int order[300007];long long t[300007],ans[300007];i ...

  4. Ocelot(二)- 请求聚合与负载均衡

    Ocelot(二)- 请求聚合与负载均衡 作者:markjiang7m2 原文地址:https://www.cnblogs.com/markjiang7m2/p/10865511.html 源码地址: ...

  5. hdu2586(lca模板 / tarjan离线 + RMQ在线)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意: 给出一棵 n 个节点的带边权的树, 有 m 个形如 x y 的询问, 要求输出所有 x, ...

  6. 洛谷P3478 [POI2008]STA-Station

    P3478 [POI2008]STA-Station 题目描述 The first stage of train system reform (that has been described in t ...

  7. springmvc ajax 简单例子

    1.控制器曾 @Controller public class AjaxController { @RequestMapping("/ajax") public void ajax ...

  8. Ryzen 移动平台上安装 Gentoo Linux

    Linux 内核对于跟进支持 Ryzen 移动低压 CPU 的热情似乎和市面上寥寥无几的 Ryzen 笔记本热度十分吻合.虽然从 Linux 4.11 起就对 Ryzen 桌面 CPU 有较好的支持, ...

  9. Jdk升级到11引起的问题:程序包javax.xml.bind.annotation不存在

    Jdk12 都发布了, 我也下载一个玩一玩吧.刚准备要下载,发现之前已经下载了一个11, 那就11 吧,也不用太新了. 安装了jdk11,习惯性的设置了一下环境变量: JAVA_HOME=D:\too ...

  10. php微信公众号开发简单记录

    开发前准备:1.服务器 2.微信公众号测试号(有真实的账号更好) 测试号申请地址:https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/lo ...