[勇者闯LeetCode] 190. Reverse Bits
[勇者闯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相关推荐
- LeetCode 190. Reverse Bits (算32次即可)
题目: Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 ...
- leetcode 190. Reverse Bits | 190. 颠倒二进制位(移位操作,十进制二进制相互转换,打表法)
题目 https://leetcode-cn.com/problems/reverse-bits/ 题解 方法1:JDK 自带的 Integer.reverse() 方法源码 /*** Returns ...
- [勇者闯LeetCode] 191. Number of 1 Bits
[勇者闯LeetCode] 191. Number of 1 Bits Description Write a function that takes an unsigned integer and ...
- [勇者闯LeetCode] 189. Rotate Array
[勇者闯LeetCode] 189. Rotate Array Description Rotate an array of n elements to the right by k steps. F ...
- [勇者闯LeetCode] 1. Two Sum
[勇者闯LeetCode] 1. Two Sum Description Given an array of integers, return indices of the two numbers s ...
- [勇者闯LeetCode] 6. ZigZag Conversion
[勇者闯LeetCode] 6. ZigZag Conversion Description The string "PAYPALISHIRING" is written in a ...
- [勇者闯LeetCode] 70. Climbing Stairs
[勇者闯LeetCode] 70. Climbing Stairs Description You are climbing a stair case. It takes n steps to rea ...
- [勇者闯LeetCode] 112. Path Sum
[勇者闯LeetCode] 112. Path Sum Description Given a binary tree and a sum, determine if the tree has a r ...
- [勇者闯LeetCode] 83. Remove Duplicates from Sorted List
[勇者闯LeetCode] 83. Remove Duplicates from Sorted List Description Given a sorted linked list, delete ...
最新文章
- 修改 Docker 的默认存储路径
- Java实现栈(顺序栈,链栈)
- leetcode BFS(python+c++)
- oracle单表存储记录,oracle从各个表获得数据保存到另一个表
- 易混淆知识点(2):display:none与visible:hidden的区别
- linux监控脚本是否运行状态,Linux Shell脚本之通过json判断应用程序内部运行状态...
- codevs——T2894 Txx考试
- 【李宏毅2020 ML/DL】P15 Why Deep-
- 华中计算机基础试题,华中科技大学2009大学计算机基础考试试题a
- 分子动力学软件-OVITO
- csdn专用必杀技----谷歌浏览器插件
- 草图大师su安装程序无法进行的解决办法。
- 互联网上免费电子图书馆网址大全
- maya导入abc动画_外包过程中的动画重定向以及蒙皮调整经验
- 国内离线安装 Chrome 扩展程序的方法总结
- C++11 lambda匿名函数看这一篇足以
- Hbase的Hmaster高可用分布式报错probably a clock skew
- 《MySQL数据库用户模块需求分析》
- 记几次被恶意挖矿程序占满linux服务器cpu的经历
- Unity 物理系统 -- 碰撞体简介(碰撞、触发条件)