public class Solution {
public uint reverseBits(uint n) {
var list = new List<uint>();//逆序的二进制列表,list[0]是最低位
while (n != )
{
var cur = n % ;
list.Add(cur);
n = n / ;
}
var addzero = - list.Count;
for (int i = ; i < addzero; i++)//补充到32位
{
list.Add();
} list.Reverse(); uint sum = ;
for (int i = ; i < list.Count; i++)
{
var cur = list[i];
sum += cur * ((uint)(Math.Pow(, i)));
}
return sum;
}
}

https://leetcode.com/problems/reverse-bits/#/description

leetcode190的更多相关文章

  1. Leetcode-190 Reverse Bits

    #190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432615 ...

  2. [Swift]LeetCode190. 颠倒二进制位 | Reverse Bits

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

  3. Java位运算总结-leetcode题目

    按位操作符只能用于整数基本数据类型中的单个bit中,操作符对应表格: Operator Description & 按位与(12345&1=1,可用于判断整数的奇偶性) | 按位或 ^ ...

随机推荐

  1. bzoj2463: [中山市选2009]谁能赢呢? 博弈

    小明和小红经常玩一个博弈游戏.给定一个n×n的棋盘,一个石头被放在棋盘的左上角.他们轮流移动石头.每一回合,选手只能把石头向上,下,左,右四个方向移动一格,并且要求移动到的格子之前不能被访问过.谁不能 ...

  2. LINUX QQ2(转载)

    关于这个话题,小编写过多次文章,也是很多朋友关心的问题. 前几日,由于小编手贱,升级Wordpress后不满意,只得重装旧版本的Wordpress,却忘了备份网站图片,导致损失惨重.近日都没有写新文章 ...

  3. 208. Implement Trie (Prefix Tree) -- 键树

    Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...

  4. IOS-static cell 与 dynamic cell 混合使用

    static cell 与 dynamic cell 混合使用 关于静态cell与动态cell的混合使用,google一下便会有很多相关文章,这里也是看过一些前辈的经验(已经忘记具体是从哪篇文章得到的 ...

  5. @pathVariable的作用

    //url中的id 可通过@pathVariable绑定到函数的参数中

  6. 从客户端中检测到有潜在危险的 Request.Form 值 方法

    由于在.net中,Request时出现有HTML或Javascript等字符串时,系统会认为是危险性值.立马报出“从客户端 中检测到有潜在危险的Request.Form值”这样的错. 解决方案一:   ...

  7. MYeclipes项目导入导出

    导入: 右键,import,

  8. 第10课 struct和union分析

    struct的小秘密:空结构体占多大内存呢? 直观的答案有两种: 1.空结构体的大小为0 2.结构体本来就是为了将不同的变量集合在一起使用的,定义空结构体会导致编译错误 实例分析: #include ...

  9. js:关闭当前页面

    var userAgent = navigator.userAgent; if (userAgent.indexOf("Firefox") != -1 || userAgent.i ...

  10. Python3.5 源码安装 Ubuntu16.04环境

    安装源码编译所需的各种依赖库:(Ubuntu16.04环境下) sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-de ...