Simple java recursive code, easy to understand


  • 0
    L

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

    }


Log in to reply
 

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