leetcode 190
190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000).
Follow up:
If this function is called many times, how would you optimize it?
Related problem: Reverse Integer
按位翻转输入的整数。
代码如下:
class Solution {
public:
uint32_t reverseBits(uint32_t n) {
unsigned ret = ;
unsigned pos1 = << ;
unsigned pos2 = ;
while(pos1)
{
if(pos1 & n)
ret |= pos2;
pos2 <<= ;
pos1 >>= ;
}
return ret;
}
};
leetcode 190的更多相关文章
- [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 (算32次即可)
题目: 190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432 ...
- [LeetCode] 190. Reverse Bits 翻转二进制位
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- Java实现 LeetCode 190 颠倒二进制位
190. 颠倒二进制位 颠倒给定的 32 位无符号整数的二进制位. 示例 1: 输入: 00000010100101000001111010011100 输出: 0011100101111000001 ...
- Leetcode 190 Reverse Bits 位运算
反转二进制 class Solution { public: uint32_t reverseBits(uint32_t n) { uint32_t ans = ; ; i<; ++i,n &g ...
- Java for LeetCode 190 Reverse Bits
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- Java [Leetcode 190]Reverse Bits
题目描述: everse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represente ...
- Leetcode 190. Reverse Bits(反转比特数)
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
随机推荐
- .split()函数使用方法
split说明 split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(list) split语法 str.split('type',num)[n] 整个语法的意思是:以 ...
- ExtJs 学习之开篇(二) Observable 给类添加监听
html:代码 DOCTYPE html><html><head><meta charset="UTF-8"><title>I ...
- java-final关键字
一.final理解 编程语言中关键字,final类不能被继承,因此final类的成员方法没有机会被覆盖,默认都是final的.在设计类时候,如果这个类不需要有子类,类的实现细节不允许改变,并且确信这个 ...
- jquery循环操作
each遍历 用法一. <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- Who is using Asio?
https://think-async.com/Asio/WhoIsUsingAsio
- TLB初始化 Missing Handler,MIPS R3K mips_init_tlb
#include <mips/r3kc0.h> LEAF(mips_init_tlb) mfc0 t0, C0_ENTRYHI # 保存ASID mtc0 zero, C0_ENTRYLO ...
- Inno Setup制作安装包的几个问题
1. 卸载时,如何判断应用程序是否运行 InnoSetup 提供变量AppMutex,用来保存应用程序的Mutex名称.现在很多应用程序都是唯一实例运行.这样避免配置文件被错误修改以及其他很多衍 ...
- 【学】AngularJS日记(4)- 过滤器的使用
过滤器: 过滤器中的 |json,可以使原来的json数据输出时按照换行的样式 过滤器 | limitTo:2可以截取字符串或者数组的前2位 过滤器| orderBy 可以进行排序,加入json里的k ...
- 关于面向切面编程Aspect Oriented Programming(AOP)
最近学到spring ,出来了一个新概念,面向切面编程,下面做个笔记,引自百度百科. Aspect Oriented Programming(AOP),面向切面编程,是一个比较热门的话题.AOP主要实 ...
- C#封装好的Win32API
Kernel.cs using System; using System.Runtime.InteropServices; using System.Text; using HANDLE = Syst ...