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.

LeetCode-342:Power of Four的更多相关文章

  1. LeetCode OJ:Power of Two(2的幂)

    Given an integer, write a function to determine if it is a power of two. 看一个数是不是2的幂,代码如下: class Solu ...

  2. 第二篇:Power BI数据可视化之基于Web数据的报表制作(经典级示例)

    前言 报表制作流程的第一步显然是从各个数据源导入数据,Power BI能从很多种数据源导入数据:如Excel,CSV,XML,以及各类数据库(SQL Server,Oracle,My SQL等),两大 ...

  3. 第一篇:Power BI数据可视化概述

    前言 "可视化之工具,可爱者甚蕃.统计学家独爱R,自Python来,世人盛爱matplotlib.余独爱Power BI之出微软而不染(免费),濯Office而不妖(够精简).......& ...

  4. leetcode算法: Find Bottom Left Tree Value

    leetcode算法: Find Bottom Left Tree ValueGiven a binary tree, find the leftmost value in the last row ...

  5. LeetCode OJ:Integer to Roman(转换整数到罗马字符)

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  6. Tool:Power Designer

    ylbtech-Tool:Power Designer 1.返回顶部 1. PowerDesigner最初由Xiao-Yun Wang(王晓昀)在SDP Technologies公司开发完成.Powe ...

  7. Leetcode 542:01 矩阵 01

    Leetcode 542:01 矩阵 01 Matrix### 题目: 给定一个由 0 和 1 组成的矩阵,找出每个元素到最近的 0 的距离. 两个相邻元素间的距离为 1 . Given a matr ...

  8. LeetCode 133:克隆图 Clone Graph

    题目: 给定无向连通图中一个节点的引用,返回该图的深拷贝(克隆).图中的每个节点都包含它的值 val(Int) 和其邻居的列表(list[Node]). Given a reference of a ...

  9. LeetCode 155:最小栈 Min Stack

    LeetCode 155:最小栈 Min Stack 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- ...

  10. LeetCode 622:设计循环队列 Design Circular Queue

    LeetCode 622:设计循环队列 Design Circular Queue 首先来看看队列这种数据结构: 队列:先入先出的数据结构 在 FIFO 数据结构中,将首先处理添加到队列中的第一个元素 ...

随机推荐

  1. Asp.Net Core App 部署故障示例 1

    相关阅读:Windows + IIS 环境部署Asp.Net Core App 1.  HTTP Error 502.5 – Process Failure 环境 Windows Server 201 ...

  2. TreeMap源代码深入剖析

    第1部分 TreeMap介绍 A Red-Black tree based NavigableMap implementation. The map is sorted according to th ...

  3. [Linux]在终端启动程序关闭终端不退出的方法

    一般情况下关闭终端时,那么在这个终端中启动的后台程序也会终止,要使终端关闭后,后台程序保持执行,使用这个指令: nohup 命令 & 如:nohup test.sh & 回车,然后提示 ...

  4. java之 22天 GUI 图形界面编程(一)

    转自:http://takeme.iteye.com/blog/1876850 GUI(图形用户界面) import java.awt.Button; import java.awt.FlowLayo ...

  5. 【计算机网络】详解网络层(二)ARP和RARP

    ARP ARP(Address Resolution Protocol,地址解析协议)是将IP地址解析为以太网MAC地址(物理地址)的协议.在局域网中,当主机或其他网络设备有数据要发送给另一个主机或设 ...

  6. Volley框架的介绍使用

    Volley是在2013年的Google I/O 2013大会上发布的,是我们的网络通信更快,更简单,更方便.对于初学者来讲是一个很好的框架. 简单来说,它提供了如下的便利功能: JSON,图像等的异 ...

  7. Godaddy ssl续费更新问题总结

    之前客户在Godaddy 上购买的ssl证书过期了,但客户续费后打开https时却提示证书过期了 进行Godaddy 后台看到证书确实是过期的 但在账户里也确实看到ssl续费成功了 猜想可能是ssl续 ...

  8. linux下设置 git ssh 代理

    /root/.ssh (以下为 root权限的操作) 1. 生成key. $ ssh-keygen 一路回车,直到生成 id_rsa, id_rsa.pub 1.1 chmod 400 id_rsa. ...

  9. FM同步数据库中结构已经发生变化的表

    接触Cognos很久了,最近遇到一个小问题. 在FM模型设计的过程中,有一张表jd_f_order.之后为了更全面的分析这个数据,在这个事实表中引入了一个新的字段商品类型字段,结构如图 但是由于jd_ ...

  10. 机器视觉之 ICP算法和RANSAC算法

    临时研究了下机器视觉两个基本算法的算法原理 ,可能有理解错误的地方,希望发现了告诉我一下 主要是了解思想,就不写具体的计算公式之类的了 (一) ICP算法(Iterative Closest Poin ...