Problem 190: Reverse Bits
思路
这道题的思路就是首先保留原先的 bit,同时 reverse bit 的顺序
保留原先 bit :
n & 1
,这样 0 还是 0 ,1 还是 1然后用 shift 的形式连接 bit,原来是从右向左,现在一连接就相当于 “reverse” 了 bits
Follow Up
If this function is called many times, how would you optimize it?
PreviousProblem 421: Maximum XOR of Two Numbers in an ArrayNextProblem 318: Maximum Product of Word Lengths
Last updated