leetcode power of two
来源:互联网 发布:淘宝win10激活码哪里买 编辑:程序博客网 时间:2024/06/12 21:02
https://leetcode.com/problems/power-of-two/
understanding:
我的方法就是取log,判断是不是整数。网上找到更好的办法一句话就完成。
best code:
url http://bookshadow.com/weblog/2015/07/06/leetcode-power-of-two/
class Solution: # @param {integer} n # @return {boolean} def isPowerOfTwo(self, n): return n > 0 and n & (n - 1) == 0
my code:
import mathclass Solution(object): def isPowerOfTwo(self, n): """ :type n: int :rtype: bool """ if n <= 0: return False tmp = math.log(n)/math.log(2) print tmp a = int(tmp) b = tmp*10 c = b - a*10 print [a,b,c] if c > 1e-10: return False else: return True
0 0
- [LeetCode] Power of Two
- 【LeetCode】Power of Two
- [Leetcode]Power of Two
- [leetCode] Power of Two
- leetcode --Power of Two
- leetcode: Power of Two
- LeetCode Power of Two
- [LeetCode] Power of Two
- LeetCode Power of Two
- [leetcode] Power of Two
- [Leetcode]Power of Two
- Leetcode: Power of Two
- [LeetCode]Power of Two
- leetcode | Power of Two
- 【leetcode】Power of Two
- [LeetCode]Power of Two
- [leetcode] Power of two
- LeetCode Power of Two
- 如何实现基于UDP的socket的通信
- Qt 创建菜单
- iOS小技巧积累
- [Cocoa]_[多语言翻译]
- shell修改文件名
- leetcode power of two
- spring security 自定义登陆 - AJAX
- 对用户定义的完整性的认识
- 计算机经典书籍
- C++ 形参与实参的传递
- LeetCode 27:Remove Element
- 汇编中定义数组与变量
- Arch linux 安装教程(2015.11.01)
- [转]F5负载均衡环境下某应用故障分析案例