[LeetCode 190]Reverse Bits
来源:互联网 发布:java程序开发培训价格 编辑:程序博客网 时间:2024/06/17 03:43
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as00111001011110000010100101000000).
Follow up:
If this function is called many times, how would you optimize it?
public int reverseBits(int n) { int[] bits = new int[32]; Arrays.fill(bits, 0); int num = 0; if(n<0){ bits[31] = 1; n = n^ Integer.MIN_VALUE; } for(int i=0;i<bits.length-1;i++){ bits[i] = n%2; n /=2; } for(int i=1;i<bits.length;i++){ num<<=1; num+=bits[i]; } return (bits[0]==1)? num|Integer.MIN_VALUE:num; }
0 0
- leetCode #190 reverse bits
- LeetCode 190 Reverse Bits
- [LeetCode][190][Reverse Bits]
- LeetCode(190) Reverse Bits
- [LeetCode 190]Reverse Bits
- LeetCode #190 Reverse Bits
- [leetcode 190]Reverse Bits
- LeetCode 190 Reverse Bits
- leetCode 190-Reverse Bits
- leetcode-190 Reverse Bits
- LeetCode 190 Reverse Bits
- leetcode 190 Reverse Bits
- LeetCode 190 :Reverse Bits
- 【leetcode 190 Reverse Bits 】
- leetcode 190:Reverse Bits
- Reverse Bits (leetcode 190)
- leetcode[190]:Reverse Bits
- leetcode-190-Reverse Bits
- Android布局笔记
- codeforces 343A Rational Resistance
- 关于解压文档名中文出现乱码解决方案
- iOS -- git的常用命令,使用步骤
- 一道SQL面试例题 if...else 与聚集函数
- [LeetCode 190]Reverse Bits
- C++编译器无法捕捉到的8种错误
- linux命令中的head命令
- CSS3手机浏览器兼容情况
- PHP初学-io操作
- linux shell “(())” 双括号运算符使用
- JVM调优总结 -Xms -Xmx -Xmn -Xss
- CSDN学院 免费技术答疑公开课,本周四场即将开播~~~
- weblogic11G超详细安装及配置教程