Home [Easy] Power of Two
Post
Cancel

[Easy] Power of Two

‘Power of Two (Easy)`


📌 Problem

https://leetcode.com/problems/power-of-two/

📌 Answer

1
2
3
4
5
6
7
8
class Solution {
    public boolean isPowerOfTwo(int n) {
        if (n == 1) return true;
        if (n == 0) return false;
        if (n % 2 != 0) return false;
        return isPowerOfTwo(n / 2);
    }
}
This post is licensed under CC BY 4.0 by the author.

[Easy] Fibonacci Number

[Medium] All Possible Full Binary Trees

Comments powered by Disqus.