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. cf812 C 二分

    C. Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. 006PHP文件处理—— 目录操作 删除目录 删除置顶类型文件

    <?php /** * 目录操作 删除目录 删除置顶类型文件 */ //echo rmdir('61') or die('目录删除失败'); //删除一个目录中有其他文件的内容的方法: //第1 ...

  3. hdu 3689 杭州 10 现场 J - Infinite monkey theorem 概率dp kmp 难度:1

    J - Infinite monkey theorem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

  4. History of programming language

    1940之前 第一个编程语言比现代的计算机还早诞生.首先,这种语言是种编码(en:code). 于1801年发明的提花织布机(或称甲卡提花织布机,英文:en:Jacquard loom),运用打孔卡上 ...

  5. New Concept English Two 30 82

    $课文80  水晶宫 867. Perhaps the most extraordinary building of the nineteeth century was the Crystal Pal ...

  6. trello 项目管理开启卡片图片显示

    /********************************************************************************* * trello 项目管理开启卡片 ...

  7. ZetCode PyQt4 tutorial Drag and Drop

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This is a simple ...

  8. Python基础知识记录

    1.去除空格 strip()  删除两边的空格.lstrip() 删除左边的空格.rstrip() 删除右边的空格 2.字符串的连接 s1='abc'  s2='cdf' s3=s1+s2    pr ...

  9. CentOS 6.5系统安装编译安装MySQL 5.6详细过程

    点评:CentOS 6.5下通过yum安装的MySQL是5.1版的,比较老,那我们就通过源代码安装高版本的MySQL5.6.14.一:卸载旧版本使用下面的命令检查是否安装有MySQL Server r ...

  10. nginx禁止非sever_name指定域名访问

    禁止非sever_name指定域名访问,将其访问指向默认站点: 设置非server_name指定域名访问,将该访问重写到test.1comserver { listen 80 default; rew ...