Java [Leetcode 190]Reverse Bits
题目描述:
everse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as00111001011110000010100101000000).
解题思路:
移位操作。
代码如下:
public class Solution {
// you need treat n as an unsigned value
public int reverseBits(int n) {
int res = 0;
for(int i = 0; i < 32; i++){
res += n & 1;
if(i < 31)
res <<= 1;
n >>>= 1;
}
return res;
}
}
Java [Leetcode 190]Reverse Bits的更多相关文章
- LeetCode 190. Reverse Bits (算32次即可)
题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...
- Java for 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 of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 ...
- 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 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 in ...
- Leetcode 190 Reverse Bits 位运算
反转二进制 class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t ans = ; ; i<; ++i,n &g ...
- 【一天一道Leetcode】#190.Reverse Bits
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 我的个人博客已创建,欢迎大家持续关注! 一天一道le ...
- 【LeetCode】190. Reverse Bits 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 二进制字符串翻转 位运算 日期 题目地址:https://le ...
随机推荐
- 【锋利的JQuery-学习笔记】菜单栏及其2级菜单
效果图: 鼠标移动到菜单项后如下: html: <div id="nav" class="mainNav"> <ul class=" ...
- spring mvc 经典总结
概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Spring 2.5 又为 Spring MVC 引入了注解驱动功能.现在你无须让 Controller 继承任何接口,无需在 ...
- POJ 2299 Ultra-QuickSort (排序+数据离散化+求顺序数)
题意:给出一个序列,求至少需要用到多少次操作,才能将序列从小到大排序. 思路: 数据量很大,n<500000,所以用冒泡模拟是超时的. 接下来就想到了求顺序数,总共需要交换的次数为每个数后面有多 ...
- mac上eclipse上配置hadoop
在mac上安装了eclipse之后,配置hadoop其实跟在linux上配置差不多,只是mac上得eclipse和界面和linux上得有点不同. 一:安装eclipse eclipse得安装比较简单, ...
- 文件夹和文件、Path类、流、序列化
循环访问目录树 参考: http://msdn.microsoft.com/zh-cn/library/bb513869.aspx 循环访问目录树”的意思是在指定的根文件夹下,访问每个嵌套子目录中任意 ...
- HDU 1164 Eddy's research I
题目链接 题意 : 给你一个数,让你用它的素数质因子表示出来. 思路 : 先打一下表,因为会有重复的质因子,所以从大到小开始找,并且找到一个之后不能就接着往下找,要再找一遍这个数. #include ...
- 简单易懂的现代魔法——Play Framework攻略4
接前文:简单易懂的现代魔法——Play Framework攻略3 1.The Object 时隔2个多月,Play Framework系列又更新了,本次的主题是:利用Play Framework实现R ...
- 获取SqlDataReader的列名
SqlConnection thisConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionSt ...
- 使用load()方法异步请求数据
使用load()方法通过Ajax请求加载服务器中的数据,并把返回的数据放置到指定的元素中,它的调用格式为: load(url,[data],[callback]) 参数url为加载服务器地址,可选项d ...
- lintcode:Length of Last Word 最后一个单词的长度
题目: 最后一个单词的长度 给定一个字符串, 包含大小写字母.空格' ',请返回其最后一个单词的长度. 如果不存在最后一个单词,请返回 0 . 样例 给定 s = "Hello World& ...