s***g 发帖数: 1250 | 1 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 many times, how would you optimize it?
这个followup应该怎么解决呢?之前其他的题也被问过类似的问题。谢谢 | b**********5 发帖数: 7881 | 2 我想是precalculation, 然后存hashtable, key是integer, value就是reversed的
integer
【在 s***g 的大作中提到】 : 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 many times, how would you optimize it? : 这个followup应该怎么解决呢?之前其他的题也被问过类似的问题。谢谢
| l*y 发帖数: 70 | 3 2^32个long 是32G要存成map更大。
不如存2^16个int的map,算的时候分两段ab各长16bit,分别翻一下再倒过来。
如果认为512KB还大可同理分4个8-bit... |
|