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 数据结构中,将首先处理添加到队列中的第一个元素 ...
随机推荐
- @JVM垃圾回收机制的一些概念
数据类型 Java虚拟机中,数据类型可以分为两类:基本数据类型和引用数据类型 .基本类型的变量保存的值就是数值本身:而引用类型的变量保存引用值."引用值"代表了某个对象的引用,而不 ...
- SVN jsvnadmin 安装与基本使用
1. jsvnadmin 介绍 https://code.google.com/p/jsvnadmin/ Svn Admin是一个Java开发的管理Svn服务器的项目用户的web应用.安装好Svn服 ...
- Android -- Gradle
使用gradle的目的 更容易重用资源和代码: 可以更容易创建不同的版本的程序,多个类型的apk包: 更容易配置,扩展; 更好的IDE集成; Gradle基本结构 使用ide创建的gradle构建的项 ...
- Tomcat gzip果然强大,js文件压缩率50%以上
Tomcat配置使用gzip,在server.xml中 <Connector port="9098" protocol="HTTP/1.1" connec ...
- C# GDI+技术
C# GDI+技术 GDI+概述 GDI+是GDI(即Windows早期版本号中附带的Graphics Device Interface)的后继者.它是一种构成Windows XP操作 ...
- [Bash] Create Aliases in .bash_profile for Common Bash Commands
.bash_profile is a file that bash invokes (or more technically sources) before the start of a new ba ...
- [Javascript]1. Improve you speed! Loop optimaztion
/** Improve you loop code */ var treasureChest = { goldCoins: 10000, magicalItem : "Crown of Sp ...
- [Node.js]25. Level 5. Route params
Create a route that responds to a GET request '/quotes/<name>', then use the param from the UR ...
- linux的子进程调用exec( )系列函数
exec( )函数族 : 以下我们来看看一个进程怎样来启动还有一个程序的运行.在Linux中要使用exec函数族.系统调用execve()对当前进程进行替换,替换者为一个指定的程序,其參数包含文件名称 ...
- Proguard随笔
- ProGuard是一个压缩.优化和混淆Java字节码,它能够删除字节码中无用的类.字段.方法和无用的凝视,还能够对类.字段.方法和属性进行混淆. - 字节码事实上包括了大量的调试信息,从而非常ea ...