LeetCode--190. 颠倒二进制位(java)

原题链接

	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 ;
    }
发布了29 篇原创文章 · 获赞 3 · 访问量 1461

猜你喜欢

转载自blog.csdn.net/QinLaoDeMaChu/article/details/104044990