Did Anyone Else Here Use Recursion? Java


  • 0
    B

    My Java solution for the problem:
    `public class Solution {

    public boolean isPowerOfTwo(int n) {
        if(n==1) return true;
        if(n%2==1) return false;
        return n==0?false:(n/2 == 2 || isPowerOfTwo(n/2));
    }
    

    }`


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.