Two lines solution (Python)


  • 1
    M
    table=[0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]
    class Solution:
        # @param n, an integer
        # @return an integer
        
        def reverseBits(self, n):
            return table[n&0xF]<<28       | table[n>>4&0xF]<<24 	|  \
    		table[n>>8&0xF]<<20   | table[n>>12&0xF]<<16    |  \
    		table[n>>16&0xF]<<12  | table[n>>20&0xF]<<8 	|  \
    		table[n>>24&0xF]<<4   | table[n>>28&0xF]
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.