LeetCode 192:Reverse Bits
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).
Follow up: If this function is called many times, how would you optimize it?
这个问题就是一个数字移位和赋值的问题,每次取出源操作数的最低位赋给目标操作数,并且源操作数右移一位,目标操作数左移一位。
class Solution {
public:
uint32_t reverseBits(uint32_t n)
{
uint32_t iRet = 0;
uint32_t iRes = n; for(int i = 0; i != 32; ++i)
{
iRet <<= 1;
iRet = iRet | iRes & 1;
iRes >>= 1;
}
return iRet;
}
};
学习了c++的移位运算,c++还是弱的不行,慢慢学,不放弃,总会有改变的!!!
LeetCode 192:Reverse Bits的更多相关文章
- LeetCode OJ:Reverse Bits(旋转bit位)
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【LeetCode】190. Reverse Bits
题目: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented ...
- Leetcode 344:Reverse String 反转字符串(python、java)
Leetcode 344:Reverse String 反转字符串 公众号:爱写bug Write a function that reverses a string. The input strin ...
- leetcode:Reverse Bits
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【一天一道Leetcode】#190.Reverse Bits
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 我的个人博客已创建,欢迎大家持续关注! 一天一道le ...
- 【LeetCode】190. Reverse Bits 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二进制字符串翻转 位运算 日期 题目地址:https://le ...
- LeetCode 【190. Reverse Bits】
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【刷题-LeetCode】190 Reverse Bits
Reverse Bits Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 0000001010010100000 ...
- LeetCode算法题-Reverse Bits(Java实现)
这是悦乐书的第185次更新,第187篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第44题(顺位题号是190).给定32位无符号整数,求它的反转位.例如: 输入:4326 ...
随机推荐
- Jenkins - 持续集成部署
1. 安装svn:用于checkout源码 (1)yum 安装:yum -y install subversion (2)查看svn版本信息:svnserver --version 2. 安装jdk ...
- 重写selenium 的 click()操作,使其变成隐式等待
selenium 页面常会因为页面加载慢而出现element 不能被点击到的情况,比如加载过程中出现遮罩,导致element 可见不可点.以下方法重写click(),用隐式等待解决这个问题. 基本思路 ...
- Mysql性能优化一:SQL语句性能优化
这里总结了52条对sql的查询优化,下面详细来看看,希望能帮助到你 1, 对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2,应尽量避免在 w ...
- 九度OJ--1163(C++)
#include <iostream>#include <vector> using namespace std; int main() { int n; while(cin& ...
- Python参考
python中os模块用法 自动化运维Python系列(五)之常用模块 最常用的Notepad++的快捷键 pycharm快捷键 最全Pycharm教程(1)——定制外观 pycharm教程大全 py ...
- 前端开发神器Sublime Text2/3之安装使用(windows7/Mac)
一,到官方网站下载神器 地址:http://www.sublimetext.com/3 Sublime Text 3 配置解释(默认){// 设置主题文件“color_scheme”: “Packag ...
- 第十五次ScrumMeeting会议
第十五次Scrum Meeting 时间:2017/12/5 地点:主201 人员:全体成员 目前工作情况 名字 完成的工作 计划工作 蔡帜 -- -- 游心 完成Scrum会议记录,更新wiki游戏 ...
- 软工实践 - 第二十五次作业 Beta 冲刺(3/7)
队名:起床一起肝活队 组长博客:https://www.cnblogs.com/dawnduck/p/10116979.html 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过 ...
- direct.h头文件(对目录操作)
chdir()改变当前目录的函数原形:int chdir(const char *path)功能:把由path指定的目录改为当前目录.path参数中可以指定驱动器号,如“a:\\ddd”, 但只是改变 ...
- MFC 相关类、函数
timeSetEvent()函数 CRectTracker类的使用 SetLocalTime设置本地时间 AdjustTokenPrivileges启用权限