You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Reverse bits of a given 32 bits unsigned integer.
10
+
#
11
+
#Example 1:
12
+
#
13
+
#Input: 00000010100101000001111010011100
14
+
#Output: 00111001011110000010100101000000
15
+
#Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000.
16
+
#Example 2:
17
+
#
18
+
#Input: 11111111111111111111111111111101
19
+
#Output: 10111111111111111111111111111111
20
+
#Explanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471 which its binary representation is 10111111111111111111111111111111.
21
+
classSolution:
22
+
defreverseBits(self, n):
23
+
tmp='{0:032b}'.format(n) #Initialize tmp and find binary representation
24
+
tmpReverse=tmp[::-1] #Reverse the tmp
25
+
returnint(tmpReverse, 2) #Return tmpReverse base 2
0 commit comments