Leetcode 342 Power of Four
2016-05-19 17:13
381 查看
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
Example:
Given num = 16, return true. Given num = 5, return false.
Follow up: Could you solve it without loops/recursion?
满足是power of 2的条件再加上减一后能被三整除
Example:
Given num = 16, return true. Given num = 5, return false.
Follow up: Could you solve it without loops/recursion?
满足是power of 2的条件再加上减一后能被三整除
class Solution(object): def isPowerOfFour(self, num): return num > 0 and num&(num-1) == 0 and (num-1)%3 == 0
相关文章推荐
- 树
- R求一个时间前N天的时间点
- puppet安装配置及使用
- Oracle导入导出数据
- VB…………………………
- 职业规划 - DREAM START
- 亚像素图像图像平移
- Android 录像保存后在文件管理或相册里不显示问题
- 腾讯tlog黑盒实现(伪代码)
- 学习使用的PL/0编译器增强版PL/0plusplusCompiler(五)使用<>代替#不等于号
- pwd,cd,type
- MySQL左连接,右连接,内连接,union
- JS技巧
- jQuery.html() .text()和.val() 的用法
- <从PAXOS到ZOOKEEPER分布式一致性原理与实践>读书笔记-第5章zookeeper使用
- SwipeRefreshLayout设置进度条的高度
- C# Interface
- 简易 的QQ APP登录以及注册页面的实现
- Linux下Redis数据库的安装方法与自动启动脚本分享
- Unity3d 顶点着色器传入的顶点数据