The problem comes with this follow up:
If this function is called many times, how would you optimize it?
I thought at it, but I cannot answer this question. Any hints?
FWIW, here's my solution (Python):
class Solution(object): def reverseBits(self, n): m = 0 for i in xrange(32): m = (m << 1) | (n & 1) n >>= 1 return m
Sorry, but I fail to see how divide and conquer alone can help. Perhaps, do you mean divide and conquer + memoization?
A lookup table can be used to achieve O(1) time complexity. Here is a link you may find helpful. All credits for the top answer.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.