LeetCode-342:Power of Four
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的更多相关文章
- LeetCode OJ:Power of Two(2的幂)
Given an integer, write a function to determine if it is a power of two. 看一个数是不是2的幂,代码如下: class Solu ...
- 第二篇:Power BI数据可视化之基于Web数据的报表制作(经典级示例)
前言 报表制作流程的第一步显然是从各个数据源导入数据,Power BI能从很多种数据源导入数据:如Excel,CSV,XML,以及各类数据库(SQL Server,Oracle,My SQL等),两大 ...
- 第一篇:Power BI数据可视化概述
前言 "可视化之工具,可爱者甚蕃.统计学家独爱R,自Python来,世人盛爱matplotlib.余独爱Power BI之出微软而不染(免费),濯Office而不妖(够精简).......& ...
- leetcode算法: Find Bottom Left Tree Value
leetcode算法: Find Bottom Left Tree ValueGiven a binary tree, find the leftmost value in the last row ...
- 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 ...
- Tool:Power Designer
ylbtech-Tool:Power Designer 1.返回顶部 1. PowerDesigner最初由Xiao-Yun Wang(王晓昀)在SDP Technologies公司开发完成.Powe ...
- Leetcode 542:01 矩阵 01
Leetcode 542:01 矩阵 01 Matrix### 题目: 给定一个由 0 和 1 组成的矩阵,找出每个元素到最近的 0 的距离. 两个相邻元素间的距离为 1 . Given a matr ...
- LeetCode 133:克隆图 Clone Graph
题目: 给定无向连通图中一个节点的引用,返回该图的深拷贝(克隆).图中的每个节点都包含它的值 val(Int) 和其邻居的列表(list[Node]). Given a reference of a ...
- LeetCode 155:最小栈 Min Stack
LeetCode 155:最小栈 Min Stack 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- ...
- LeetCode 622:设计循环队列 Design Circular Queue
LeetCode 622:设计循环队列 Design Circular Queue 首先来看看队列这种数据结构: 队列:先入先出的数据结构 在 FIFO 数据结构中,将首先处理添加到队列中的第一个元素 ...
随机推荐
- HTTP参数CONNETCTION_TIMEOUT和SO_TIMEOUT区别
在开发中经常碰到这两个参数,但是之前对它们的真正含义一直比较模糊,今天通过调试程序并且结合官方文档,了解了两者的含义与区别. 参数的定义直接去看官方的文档(httpcore-4.3) org.apac ...
- [16] 螺旋面(Spire)图形的生成算法
顶点数据的生成 bool YfBuildSpireVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices, Yu ...
- C++分布式实时应用框架——系统管理模块
一个分布式实时系统集群动辄上百台机器,集群的规模已经限定这将是一个”封闭“的系统.你不可能再一台台去操作上百台机器,传统的人工运维方式早已不能满足当下需要,所有对集群或者集群中某个节点的操作都必需通过 ...
- Git的简单介绍
每次看到别人写Git的文章,同学中也有用Git感觉很高大上的感觉,工作中用的是SVN,周末倒腾了一下Git,Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.Git 与 ...
- Merge Two Sorted Lists leetcode java
题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splici ...
- 6个原则、50条秘技提高HTML5应用及网站性能
Jatinder Mann是微软Internet Explorer产品的一名项目经理,在BUILD 2012大会上,他做了题为“提高HTML5应用和网站性能的50条秘技(50 performance ...
- JavaScript的js文件压缩和格式化工具
JavaScriptcompressor.com这个网站可是大名鼎鼎啊.以前在找到过压缩 Javascript 代码的程序,一直在用,感觉效果不错.域名是: http://javascriptcomp ...
- word 文档如何加密
给Word文档加密主要有以下几个方法:文件加密文件菜单设置:1.打开需要加密的Word文档.2.选“文件”的“另存为”,出现“另存为”对话框,在“工具”中选“常规选项”,出现“保存”选项卡.3.分别在 ...
- 2017.8.30 elasticsearch-sql的安装与使用
参考来自: http://blog.csdn.net/u012307002/article/details/52837756 https://github.com/NLPchina/elasticse ...
- asp.net网站项目调用page,或者ashx页面不能用反射
public class TestHandler : System.Web.IHttpHandler { public bool IsReusable { get { return false; } ...