Skip to content

Commit a1bcf60

Browse files
committed
Adding Simple Solution - 190 - Reverse Bits
1 parent 82660f2 commit a1bcf60

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Reverse_Bits/SimpleSolution.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
##==================================
2+
## Leetcode
3+
## Student: Vandit Jyotindra Gajjar
4+
## Year: 2020
5+
## Problem: 190
6+
## Problem Name: Reverse Bits
7+
##===================================
8+
#
9+
#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+
class Solution:
22+
def reverseBits(self, n):
23+
tmp = '{0:032b}'.format(n) #Initialize tmp and find binary representation
24+
tmpReverse = tmp[::-1] #Reverse the tmp
25+
return int(tmpReverse, 2) #Return tmpReverse base 2

0 commit comments

Comments
 (0)