- 浏览: 173770 次
- 性别:
- 来自: 济南
文章分类
最新评论
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).
给定一个无符号的整数,将它的每个比特位都逆转,返回逆转之后新的数。通过位运算,取32个不同位上的数字,同时通过左移来得到结果。代码如下:
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000).
给定一个无符号的整数,将它的每个比特位都逆转,返回逆转之后新的数。通过位运算,取32个不同位上的数字,同时通过左移来得到结果。代码如下:
public class Solution { // you need treat n as an unsigned value public int reverseBits(int n) { int result = 0; for(int i = 0; i < 32; i++) { result <<= 1; result |= (n >> i & 1); } return result; } }
发表评论
-
498. Diagonal Traverse
2019-11-15 13:52 227Given a matrix of M x N eleme ... -
496 Next Greater Element I
2019-11-14 13:50 228You are given two arrays (witho ... -
Word Break II
2016-03-09 03:15 343Given a string s and a dictiona ... -
Insert Interval
2016-03-08 02:11 335Given a set of non-overlapping ... -
Merge Intervals
2016-03-07 05:25 451Given a collection of intervals ... -
Merge k Sorted Lists
2016-03-07 04:03 513Merge k sorted linked lists and ... -
Multiply Strings
2016-03-06 07:27 431Given two numbers represented a ... -
N-Queens II
2016-03-06 03:06 622Follow up for N-Queens problem. ... -
N-Queens
2016-03-06 02:47 428The n-queens puzzle is the prob ... -
First Missing Positive
2016-03-05 03:09 388Given an unsorted integer array ... -
Spiral Matrix
2016-03-04 03:39 519Given a matrix of m x n element ... -
Trapping Rain Water
2016-03-04 02:54 534Given n non-negative integers r ... -
Repeated DNA Sequences
2016-03-03 03:10 371All DNA is composed of a series ... -
Increasing Triplet Subsequence
2016-03-02 02:48 862Given an unsorted array return ... -
Maximum Product of Word Lengths
2016-03-02 01:56 883Given a string array words, fin ... -
LRU Cache
2016-02-29 10:37 555Design and implement a data str ... -
Super Ugly Number
2016-02-29 07:07 601Write a program to find the nth ... -
Longest Increasing Path in a Matrix
2016-02-29 05:56 765Given an integer matrix, find t ... -
Coin Change
2016-02-29 04:39 736You are given coins of differen ... -
Minimum Height Trees
2016-02-29 04:11 630For a undirected graph with tre ...
相关推荐
Reverse Bits Repeated DNA Sequences Number of 1 Bits Gray Code Single Number Single Number II Single Number III Power of Two Missing Number Maximum Product of Word Lengths Bitwise AND of Numbers Range...
190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits/) | [C++](./C++/reverse-bits.cpp) [Python](./Python/reverse-bits.py) | _O(1)_ | _O(1)_ | Easy ||| 191 |[Number of 1 Bits]...
Reverse Bits 二进制位数 二进制的&和>> << >>== 20200525 172. Factorial Trailing Zeroes 数学分析 递归和循环 20200525 191. Number of 1 Bits 二进制 二进制如何记录1的个数 20200526 287. Find the ...
Worging with bit variables on movicon
231 Counting Bits 561 232 Maximum Product of Word Lengths 563 233 Gray Code 565 234 Permutations 567 235 Permutations II 571 236 Permutation Sequence 573 237 Generate Parentheses 575 238 Combination ...
反向位 反转 64 位整数的位。
Reverse the order of bits in an unsigned integer Chapter 20. Convert an integer to a string and a string to an integer Chapter 21. Convert a number from base b1 to base b2 Chapter 22. Given a set S, ...
Hopper is a reverse engineering tool for OS X and Linux, that lets you disassemble, decompile and debug your 32/64bits Intel Mac, Linux, Windows and iOS executables!
3. reverse_bits.c 占用一个字节的函数,一点一点地反转它。 237 => 1110 1101 after reverse 1101 1110 => 222 4. sort_int_tab.c 函数按升序对int数组进行排序(就地),该数组包含正好是'size'元素。 用于始终...
If you don't trust this tool, don't use it or even better, reverse engineer the keygeneration and tell me about your worries ;-) - The bignumber library used in this program is MIRACL 4.45 (c) by ...
██╗ ██████╗ ██╗ ██████╗ ██╗████████╗███████╗ ██║ ██╔═══██╗██║ ██╔══██╗██║╚══██╔══╝██╔════╝ ██║ ██║ ██...
examshell02 此考试外壳适用于希望为期末考试进行培训的人,练习将在适当的时候添加。 在此考试中,您将需要知道如何使用以下工具: ft_putstr ft_strlen 生成文件 ... reverse_bits ft_rrange
===========公司明智的编码问题============= ...9. Prime Number of Set Bits 10. Reverse Each Word in String 11. Find k-th character in string 12. Star Elements 13. Common Subsequence 14. Choco
LeetCode算法蛇形走位 This is a record of my exploring leetcode Overview Problem Solution no need to solve math BF findKth most common way std::reverse Finite State Machine brute ...bits
Bits(二进制中有多少个1) 、 / Easy Repeated DNA Sequences Medium Single Number(落单的数) 、 / Medium Single Number II(落单的数 II) 、 Medium Single Number III(落单的数 III) Medium Hash Function(哈希...
+ remote_tables.tv_remote_config_table.KEY_REVERSE + " blob, " + remote_tables.tv_remote_config_table.KEY_PIP + " blob);"; 2. insert one group of data into the table; 3. implement the UI, please ...
Bitset& reverse(); //返回左边n位,构成新的Bitset Bitset left(size_t n) const; //返回右边n位,构成新的Bitset Bitset right(size_t n) const; //判断b包含的位数组是否是本类的位数组的自串,如果是...
Reverse, undo, and calculate CRC32 checksums positional arguments: action flip flip the bits to convert normal(msbit-first) polynomials to reversed (lsbit-first) and vice versa reciprocal find ...
Trail of Bits托管可下载的cxx-common的预构建版本,这使得使用Rellic进行安装和运行变得相当容易。 尽管如此,下表还是Rellic的大多数依赖项。 名称版最新3.14+最新最新4.0+4.0+ 4.7.1+预制Docker映像预先构建的...
Reverse option - changes direction of graph. Show traffic in Bytes / Bits - show traffic values in bits or bytes Fix Rate - Show graph data only up to "Max Rate" and don't allow automatic ...