首页 > 其他 > 详细

leetcode Power of Two

时间:2015-12-04 22:44:46      阅读:186      评论:0      收藏:0      [点我收藏+]

题目连接

https://leetcode.com/problems/power-of-two/ 

Power of Two

Description

Given an integer, write a function to determine if it is a power of two. 

水一发python。。

class Solution(object):
    def isPowerOfTwo(self, n):
    	shift = 1
    	if n == 1 or n == 2:
    		return True
    	while shift < n:
    		shift <<= 1
    	return shift == n

leetcode Power of Two

原文:http://www.cnblogs.com/GadyPu/p/5020682.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!