[抄题]:

Reverse bits of a given 32 bits unsigned integer.

Example:

Input: 43261596
Output: 964176192
Explanation: 43261596 represented in binary as 00000010100101000001111010011100,
  return 964176192 represented in binary as 00111001011110000010100101000000.

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

[一句话思路]:

32位中的每一位都左移 留出空缺、&1取出最后一位、右移丢掉

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

  1. &1相同后即可+1,统计1 的个数

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

左移 留出空缺、&1取出最后一位、右移丢掉

[复杂度]:Time complexity: O() Space complexity: O()

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

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

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. [LeetCode] 190. Reverse Bits 颠倒二进制位

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

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

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

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

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

  5. LeetCode 【190. Reverse Bits】

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

  6. Java for LeetCode 190 Reverse Bits

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

  7. 190. Reverse Bits -- 按位反转

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

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

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

  9. 190. Reverse Bits

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

随机推荐

  1. [转载] ffmpeg摄像头视频采集-采集步骤概述并采集一帧视频

    近期由于工作任务,需要开发一个跨平台视频聊天系统,其中就用到了ffmpeg进行采集与编码,网上找了一大堆的资料,虽然都有一些有用的东西,但实在太碎片化了,这几天一直在整理和实验这些资料,边整理,边做一 ...

  2. HDU - 6433: H. Pow (简答题,输出大数)

    There are n numbers 3^0, 3^1, . . . , 3^n-1. Each time you can choose a subset of them (may be empty ...

  3. HTML服务器控件与Web服务器控件

    asp.net之所以现在开发方便和快捷,关键是它有一组强大的控件库,包括web服务器控件,web用户控件,web自定义控件,html服务器控件和html控件等.这里主要整理一下html控件.html服 ...

  4. BZOJ3632: 外太空旅行

    BZOJ1547: 周末晚会 https://lydsy.com/JudgeOnline/problem.php?id=1547 分析: 对于一个串旋转若干次会回到本身,旋转次数即是同构个数,这个东西 ...

  5. 前端工程师面试问题归纳(一、问答类html/css/js基础)

    一.参考资源 1.前端面试题及答案整理(一) 2.2017年前端面试题整理汇总100题 3.2018最新Web前端经典面试试题及答案 4.[javascript常见面试题]常见前端面试题及答案 5.W ...

  6. 12C 对表分区维护的增强

    Oracle Database 12c对表分区变化比较多,共分为下面几点 1.在线移动分区:通过MOVE ONLINE关键字实现在线分区移动.移动过程中,对表和被移动的分区可以执行查询操作, DML语 ...

  7. python3之scrapy安装使用

    需要安装的包 pip install scrapy selenium 可能需要卸载重装的模块   lxml cryptography  cffi  pypiwin32 pip uninstall xx ...

  8. 【Machine Learning 学习笔记】OSX Octave 输出图像问题

    Uninstall any existing gnuplot on your OSX brew uninstall gnuplot Install gnuplot with either X or X ...

  9. mysql + unidac 使用事务例子

    //备注:mysql必须是使用innoDB引擎才支持事务功能,否则以下事务相关代码将失效.//SQL SERVER和Oracle还没试,明天回公司试了再发代码.procedure TForm1.btn ...

  10. 20位活跃在Github上的国内技术大牛

    登录|注册     leon-这个程序员不闷骚的博客 喜欢leon,有追求有原则有爱心的杀手,做一个有追求的程序员,代码是程序员的朋友,虽然没有热情,但是非常忠实.希望拥有一身绝世武功,再配一把绝世好 ...