0
0

More than 1 year has passed since last update.

Leetcode 231. Power of Two

Posted at

231. Power of Two

class Solution {
    public boolean isPowerOfTwo(int n) {
        if(n == 0){
            return false;
        }
        if(n == 1){
            return true;
        }

        while(n != 1){
            if(n % 2 == 0){
                n /= 2;
            }else{
                return false;
            }
        }
        return true;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0