This  is another  "Pick One" Problem :【Problem:342-Power of Four

Given an integer (signed  bits), write a function to check whether it is a power of .

Example:
Given num = , return true. Given num = , return false. Follow up: Could you solve it without loops/recursion?

Python Codes:

class Solution:
def isPowerOfFour(self, num):
"""
:type num: int
:rtype: bool
"""
return num !=0 and num &(num-1)==0 and num & 1431655765==num

答案是如此短小精悍!:

return num != 0 and num &(num-1) == 0 and num & 1431655765== num

1)num != 0:Obviously 0 is not power of 4。

2)num &(num-1) == 0:Any number which is power of 4, it should be power of 2, so use num &(num-1) == 0 to make sure of that.

3)num & 1431655765== num:finally  need to check that if the number 'AND' the mask value is itself, to make sure it's in the list above.

最新文章

  1. Entity Framework Core 1.1 升级通告
  2. JS原生效果瀑布流布局的实现(一)
  3. 【vbs】vbs写ini文件
  4. SET TEXTSIZE number
  5. fir.im Weekly - 每个程序员都应当拥有的技能树
  6. CSS中的 backgroundPosition 属性
  7. Linux_常用命令_03_磁盘/挂载_信息查看
  8. eclipse 书签
  9. POJ 1850 Code(组合数)
  10. Google 常用镜像收集
  11. 在WIN7/8下把XP装入VHD (下)
  12. 解决PhpStorm卡顿的问题
  13. Storm+HBase实时实践
  14. 在Linux的Terminal中显示文本文件特定行的内容
  15. Spring 事务与脏读、不可重复读、幻读
  16. window上安装kafka(单机)
  17. 软件工程(四)数据流图DFD
  18. 1066: 单词游戏(game)
  19. Maven实战(十一)eclipse下载依赖jar包出问题
  20. SCOJ 4423: Necklace polya

热门文章

  1. HBase性能调优(转)
  2. Objective-C:动态绑定
  3. DotNetBar中dotNetBarManager设置窗口 实现单文档视图界面
  4. iOS开发-委托实战
  5. JDBC上关于数据库中多表操作一对多关系和多对多关系的实现方法
  6. C# 事件(Event)
  7. Angular路由与Nodejs路由的区别
  8. ML—朴素贝叶斯
  9. 基于Teigha.Net实现CAD到SHP的转换方案
  10. Adobe Dynamic Http Streaming的简单配置与实现 (FMS, HLS, HDS)