231. Power of Two

来源:互联网 发布:美国医学PHD 知乎 编辑:程序博客网 时间:2024/06/05 09:29

题目

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

我的解法

public class Solution {    public boolean isPowerOfTwo(int n) {        if(n == 0)            return false;        while(n % 2 == 0){            n = n / 2;        }        return n == 1;    }}



0 0
原创粉丝点击