【LeetCode】 231. Power of Two

来源:互联网 发布:随机算法软件 编辑:程序博客网 时间:2024/05/23 12:07

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 > 1) {            int rest = n % 2;            if (rest == 1) {                return false;            }            n = n / 2;        }        return true;    }}


0 0