[勇者闯LeetCode] 190. Reverse Bits

Description

Reverse bits of a given 32 bits unsigned integer.

For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000).

Information

  • Tags: Bit Manipulation
  • Difficulty: Easy

Solution

result初值为0,32次循环:
每次result先左移一位,然后将n与1进行&操作取出n的最后一位,通过|操作放到result的最后一位上,n右移一位。

C++ Code

class Solution {
public:uint32_t reverseBits(uint32_t n) {uint32_t result = 0;int count = 32;while (count--) {result <<= 1;result |= n & 1;n >>= 1;}
        return result;}
};

[勇者闯LeetCode] 190. Reverse Bits相关推荐

  1. LeetCode 190. Reverse Bits (算32次即可)

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

  2. leetcode 190. Reverse Bits | 190. 颠倒二进制位(移位操作,十进制二进制相互转换,打表法)

    题目 https://leetcode-cn.com/problems/reverse-bits/ 题解 方法1:JDK 自带的 Integer.reverse() 方法源码 /*** Returns ...

  3. [勇者闯LeetCode] 191. Number of 1 Bits

    [勇者闯LeetCode] 191. Number of 1 Bits Description Write a function that takes an unsigned integer and ...

  4. [勇者闯LeetCode] 189. Rotate Array

    [勇者闯LeetCode] 189. Rotate Array Description Rotate an array of n elements to the right by k steps. F ...

  5. [勇者闯LeetCode] 1. Two Sum

    [勇者闯LeetCode] 1. Two Sum Description Given an array of integers, return indices of the two numbers s ...

  6. [勇者闯LeetCode] 6. ZigZag Conversion

    [勇者闯LeetCode] 6. ZigZag Conversion Description The string "PAYPALISHIRING" is written in a ...

  7. [勇者闯LeetCode] 70. Climbing Stairs

    [勇者闯LeetCode] 70. Climbing Stairs Description You are climbing a stair case. It takes n steps to rea ...

  8. [勇者闯LeetCode] 112. Path Sum

    [勇者闯LeetCode] 112. Path Sum Description Given a binary tree and a sum, determine if the tree has a r ...

  9. [勇者闯LeetCode] 83. Remove Duplicates from Sorted List

    [勇者闯LeetCode] 83. Remove Duplicates from Sorted List Description Given a sorted linked list, delete ...

最新文章

  1. 修改 Docker 的默认存储路径
  2. Java实现栈(顺序栈,链栈)
  3. leetcode BFS(python+c++)
  4. oracle单表存储记录,oracle从各个表获得数据保存到另一个表
  5. 易混淆知识点(2):display:none与visible:hidden的区别
  6. linux监控脚本是否运行状态,Linux Shell脚本之通过json判断应用程序内部运行状态...
  7. codevs——T2894 Txx考试
  8. 【李宏毅2020 ML/DL】P15 Why Deep-
  9. 华中计算机基础试题,华中科技大学2009大学计算机基础考试试题a
  10. 分子动力学软件-OVITO
  11. csdn专用必杀技----谷歌浏览器插件
  12. 草图大师su安装程序无法进行的解决办法。
  13. 互联网上免费电子图书馆网址大全
  14. maya导入abc动画_外包过程中的动画重定向以及蒙皮调整经验
  15. 国内离线安装 Chrome 扩展程序的方法总结
  16. C++11 lambda匿名函数看这一篇足以
  17. Hbase的Hmaster高可用分布式报错probably a clock skew
  18. 《MySQL数据库用户模块需求分析》
  19. 记几次被恶意挖矿程序占满linux服务器cpu的经历
  20. Unity 物理系统 -- 碰撞体简介(碰撞、触发条件)

热门文章

  1. qlu_新生赛_2019
  2. Android 上传Google Play 市场打包成AAB文件
  3. HTML中特殊符号的介绍
  4. 在 NVIDIA jetson tx2 上基于 realsense d435i 相机运行 vins 相关配置
  5. 算法-树-反转二叉树
  6. PyTorch构建卷积层
  7. 【啊哈!算法】算法5开启“树”之旅
  8. Centos7右上角网络图标不见了
  9. GTC2018参会小结
  10. 安盛x德勤《数字化健康》白皮书:揭示未来医疗健康产业五大趋势