‘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);
}
}
Comments powered by Disqus.