leetcode Power of Two

来源:互联网 发布:淘宝达人介绍 编辑:程序博客网 时间:2024/06/05 14:18

原题链接:https://leetcode.com/problems/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
0 0
原创粉丝点击