LeetCodeOJ_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
Tags Bit Manipulation
Similar Problems (E) Number of 1 Bits

分析:

代码:

class Solution {
public:
    uint32_t reverseBits(uint32_t n) {
        uint32_t m=0;
        for(int i=0;i<32;i++)
        {
            m=m*2+n%2;
            n=n/2;
        }
        return m;
    }
};

结果:

这里写图片描述

总结:

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012482487/article/details/49913339
文章标签: OJ 算法 c++
个人分类: LeetCodeOJ
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

LeetCodeOJ_190_Reverse Bits

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭