码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode Power of Two

时间:2015-12-04 22:46:31      阅读:121      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!