We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 56c02be commit a501932Copy full SHA for a501932
bin.power-of-two.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ """
3
+ 231. 2的幂
4
+ https://leetcode-cn.com/problems/power-of-two/
5
+ 给定一个整数,编写一个函数来判断它是否是 2 的幂次方。
6
7
+ def isPowerOfTwo(self, n: int) -> bool:
8
+ return n != 0 and n & (n - 1) == 0
9
+
10
11
+so = Solution()
12
+print(so.isPowerOfTwo(15))
bin.reverse-bits.py
@@ -0,0 +1,17 @@
+ 190. 颠倒二进制位
+ https://leetcode-cn.com/problems/reverse-bits/
+ 颠倒给定的 32 位无符号整数的二进制位。
+ def reverseBits(self, n: int) -> int:
+ res = 0
+ for i in range(32):
+ res = (res << 1) + (n & 1)
+ n = n >> 1
13
+ return res
14
15
16
17
+print(so.reverseBits(0o11111111111111111111111111111101))
0 commit comments