Please review my accepted(4ms) solution using Math.log


  • 0
    A
    public class Solution {
        public boolean isPowerOfTwo(int n) {
            if(n==0) return false;
            double x = Math.log10(n)/Math.log10(2); 
            if(Math.floor(x)==x) return true;
            else return false;
        }
    }
    

    Is the above solution good/efficient? Please comment .


Log in to reply
 

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