Java [Leetcode 190]Reverse Bits
2024-10-19 03:35:41
题目描述:
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;
}
}
最新文章
- 【腾讯bugly干货】QQ空间直播秒开优化实践
- linux 学习之路
- Socket编程基础知识
- mono for android代码记录1 WebClient Post数据到Nopcommerce(post数据到MVC5)
- 移动端H5---页面适配问题详谈(一)
- WinForm点击按钮,访问百度
- 深入浅出:Linux设备驱动之字符设备驱
- java 调用 .net webservice
- Ye.云狐J2刷机笔记 | 完美切换内部存储卡和SD卡的改法.vold.fstab
- 单片微机原理P0:80C51结构原理
- jquery append 动态添加的元素事件on 不起作用问题的解决
- [iOS]C语言技术视频-09-枚举的定义
- BZOJ2287 消失之物
- Linux文件系统的目录结构详解
- Tesseract训练
- 个人经验~mongo故障处理思路
- Vue keep-alive总结
- 特别翔实的adaboost分类算法讲解 转的
- Java程序员职业规划
- osm2pgsql windows “illegal option -W” error