LeetCode 190. Reverse Bits (算32次即可)

来源:互联网 发布:网络时钟同步设备 编辑:程序博客网 时间:2024/06/17 12:16

题目:

  1. 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

Credits:
Special thanks to @ts for adding this problem and creating all test cases.

代码:

class Solution {public:    uint32_t reverseBits(uint32_t n) {        uint32_t x = 0;        int t = 32;        while(t--){            x = x*2+n%2;            n /= 2;        }        return x;    }};
阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 溴乙酸乙酯 乙酸酐价格 乙酸酐 密度 如何除去乙酸酐 乙酸酐密度 乙酐 乙酸酐结构式 乙酸酐沸点 乙酸酐化学式 乙酸酐溶解度 乙酸酐和水反应 巯基乙酸钙 乙酸钙 乙酸乙酯的制备实验报告 乙酸乙酯结构简式 乙酸乙酯水解 无水乙酸钠价格 三水乙酸钠 脱氢乙酸钠的使用方法 脱氧乙酸钠 醋酸钠价格 氨三乙酸钠 1-萘乙酸钠 醋酸钠水解 液体醋酸钠 醋酸钠电离 醋酸钠用途 复方醋酸钠 乙酸钠多少钱一吨 脱氢乙酸钠生产厂家 萘乙酸钠 脱氢乙酸钠是什么 醋酸钠多少钱一吨 工业级乙酸钠 醋酸钠沸点 醋酸钠和盐酸 4氯苯氧乙酸钠 乙酸钠分子量 乙酸钠的作用 聚乙酸钠 双乙酸钠用量