Leetcode腾讯精选_编号:231 --python
2019-03-01 23:15
344 查看
给定一个整数,编写一个函数来判断它是否是 2 的幂次方。
示例 1:
输入: 1
输出: true
解释: 20 = 1
示例 2:
输入: 16
输出: true
解释: 24 = 16
示例 3:
输入: 218
输出: false
看了别人的, 妙啊!!
class Solution: def isPowerOfTwo(self, n): """ :type n: int :rtype: bool """ a=n&n-1 if a==0 and n!=0: return True else: return False
相关文章推荐
- Leetcode腾讯精选_编号:235 --python
- Leetcode腾讯精选_编号:236 --python
- Leetcode腾讯精选_编号:237 --python
- Leetcode腾讯精选_编号:292 --python
- Leetcode腾讯精选_编号:344 --python
- Leetcode腾讯精选_编号:557 --python
- LeetCode题解(python)-8. 字符串转换整数
- Leetcode做题日记:46. 全排列(PYTHON)
- LeetCode题解(python)-9. 回文数
- 面试笔试杂项积累-leetcode 231-235
- [python]Leetcode1-Two Sum
- Leetcode做题日记:49. 字母异位词分组(PYTHON)
- leetcode的python实现 刷题笔记70:爬楼梯(动态规划)
- 【LeetCode】Group Anagrams 解题报告(Python & Java)
- LeetCode 198. House Robber(Python)
- [LeetCode] 015. 3Sum (Medium) (C++/Java/Python)
- LeetCode 16 3Sum Closest(C,C++,Java,Python)
- [Leetcode,python] Hamming Distance 汉明距离
- LeetCode 4 — Median of Two Sorted Arrays (C++ Java Python)
- LeetCode709.转换成小写字母(python)