leetcode刷題--Reverse Bits
題目:簡單說就是求一個10進位制數的32位二進位制數首位顛倒後所得32位二進位制數的10進製表示。很繞口!但是不復雜
依然和前一題一個思路,用字串來處理
程式碼:
class Solution:
# @param n, an integer
# @return an integer
def reverseBits(self, n):
org=bin(n)[2:]
org="".join(["0" for i in range(32-len(org))])+org
rsl=""
for i in range(len(org)-1,-1,-1):
rsl += org[i]
print(rsl)
return int(rsl,2)
相關文章
- LeetCode 第 190 題 (Reverse Bits)LeetCode
- LeetCode-Reverse BitsLeetCode
- leetcode刷題--Number of 1 BitsLeetCode
- leetcode刷題--Reverse Linked ListLeetCode
- LeetCode 第 7 題(Reverse Integer)LeetCode
- LeetCode 第 191 題 (Number of 1 Bits)LeetCode
- LeetCode 第 338 題 (Counting Bits)LeetCode
- LeetCode-Count BitsLeetCode
- LeetCode刷題整理LeetCode
- leetcode刷題(一)LeetCode
- LeetCode刷題 堆LeetCode
- LeetCode 刷題—樹LeetCode
- LeetCode - 解題筆記 - 7 - Reverse IntegerLeetCode筆記
- LeetCode 刷題指南(一):為什麼要刷題LeetCode
- leetcode Reverse IntegerLeetCode
- LeetCode 刷題筆記LeetCode筆記
- leetcode刷題筆記LeetCode筆記
- LeetCode刷題記錄LeetCode
- 如何使用leetcode刷題LeetCode
- leetcode刷題--Majority ElementLeetCode
- leetcode刷題--Count PrimesLeetCode
- leetcode刷題--Rotate ArrayLeetCode
- leetcode刷題--Count and SayLeetCode
- Leetcode刷題分類LeetCode
- Leetcode刷題準備LeetCode
- LeetCode刷題—陣列LeetCode陣列
- 【LeetCode】Counting Bits(338)LeetCode
- LeetCode 338 Counting BitsLeetCode
- Leetcode 7 Reverse IntegerLeetCode
- Reverse Integer leetcode javaLeetCodeJava
- Leetcode刷題——求眾數LeetCode
- leetcode刷題筆記605LeetCode筆記
- Leetcode刷題系列彙總LeetCode
- leetcode刷題--Happy NumberLeetCodeAPP
- leetcode刷題記錄 661~LeetCode
- LeetCode刷題之第701題LeetCode
- [LeetCode] 191. Number of 1 BitsLeetCode
- Leetcode已刷題目題解彙總LeetCode