diff --git a/LeetCode/PowerOfTwo.java b/LeetCode/PowerOfTwo.java new file mode 100644 index 00000000..117ae323 --- /dev/null +++ b/LeetCode/PowerOfTwo.java @@ -0,0 +1,15 @@ +//This is leetcode quiestion power of two with a valid answer +class Solution { + public boolean isPowerOfTwo(int n) { + if (n <= 0){ + return false; + } + if (n == 1){ + return true; + } + if (n % 2 != 0){ + return false; + } + return isPowerOfTwo(n/2); + } +}