public int reverseBits(int n) {//int 类型 一共就32位
int res = 0;
for(int i = 0;i < 32;i++) {
//res 左移一位是为了腾出一个空放置 n 的最后一位
res = (res << 1) + (n & 1);
// n 的最后一位处理完了,右移一位挤掉它
n = n >> 1;
}
return res ;
}
LeetCode--190. 颠倒二进制位(java)
猜你喜欢
转载自blog.csdn.net/QinLaoDeMaChu/article/details/104044990
今日推荐
周排行