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 ...
随机推荐
- css的transition 属性
把鼠标指针放到 div 元素上,其宽度会从 100px 逐渐变为 300px: div { width:100px; transition: width 2s; -moz-transition: wi ...
- C++ explict 关键字
关键字explicit可以禁止“单参数构造函数”被用于自动类型转换class Stack{explicit Stack(int size);};没有explicit的话Stack s = 40;能编译 ...
- unity3d android互调
unityPlayer = new AndroidJavaClass("com.xxx.xxx.MainActivity"); curActivity = unityPlayer. ...
- Unity3D研究院之与Android相互传递消息
原地址:http://www.xuanyusong.com/archives/676 上一篇文章我们学习了Unity向Android发送消息,如果Android又能给Unity回馈消息那么这就玩美了. ...
- Unity3D开发之“获取IOS设备所在的国家代码"
原地址:http://dong2008hong.blog.163.com/blog/static/469688272014021025578/ 在前一段时间游戏开发中需要实现获取IOS设备所在的国家代 ...
- Maintainable HashCode and Equals Using Apache Commons
Java hashCode and equals methods can be tricky to implement correctly. Fortunately, all majors IDEs ...
- C# 面向对象之概念理解(2)
委托 如果对象A为了满足某个请求,而寻求另一个对象B的帮助,这被称作是A对B的委托. 对象间的委托,和现实世界中人与人之间的委托一样:如果你“那位”要求你在他外出公干期间帮忙助剪草坪,而你转而雇佣邻居 ...
- POJ2299Ultra-QuickSort
http://poj.org/problem?id=2299 题意 : 排序,求排序次数,本来以为用冒泡可以搞定,事实上,那么大的数据以及一个TLE告诉我,会超时......... 思路 : 问了一下 ...
- Oracle的学习三:java连接Oracle、事务、内置函数、日期函数、转换函数、系统函数
1.java程序操作Oracle java连接Oracle JDBC_ODBC桥连接 1.加载驱动: Class.forName("sun.jdbc.odbc.JdbcodbcDriver& ...
- cojs QAQ的矩阵 题解报告
题目描述非常的清晰 首先我们考虑(A*B)^m的求法,这个部分可以参考BZOJ 杰杰的女性朋友 我们不难发现(A*B)^m=A*(B*A)^(m-1)*B A*B是n*n的矩阵,而B*A是k*k的矩阵 ...