[LeetCode][Python3] 190. Reverse Bits
2018. 11. 4. 01:22 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/reverse-bits/
My Solution :
class Solution:
# @param n, an integer
# @return an integer
def reverseBits(self, n):
ans = 0
for _ in range(32):
ans = ans*2 + n%2
n //= 2
return ans
Comment :
위는 산술연산 아래는 비트연산
My Solution2 :
class Solution:
# @param n, an integer
# @return an integer
def reverseBits(self, n):
ans = 0
for _ in range(32):
ans = (ans << 1) + (n & 1)
n >>= 1
return ans
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 217. Contains Duplicate (0) | 2018.11.04 |
---|---|
[LeetCode][Python3] 204. Count Primes (0) | 2018.11.04 |
[LeetCode][Python3] 202. Happy Number (0) | 2018.11.04 |
[LeetCode][Python3] 191. Number of 1 Bits (0) | 2018.11.04 |
[LeetCode][Python3] 189. Rotate Array (0) | 2018.11.03 |
[LeetCode][Python3] 172. Factorial Trailing Zeroes (0) | 2018.11.03 |
[LeetCode][Python3] 171. Excel Sheet Column Number (0) | 2018.11.03 |
[LeetCode][Python3] 122. Best Time to Buy and Sell Stock II (0) | 2018.11.03 |
최근에 달린 댓글 최근에 달린 댓글