Java No Loop Solution, similar to the power of 2


  • 0
    E
    public class Solution {
        public boolean isPowerOfThree(int n) {
            if(n<=0){
                return false;
            }
            else if(n==1){
                return true;
            }
            else{
                int val=(int)Math.pow(3,19);
                if(val%n==0){
                    return true;
                }
            }
            return false;
        }
    }
    

Log in to reply
 

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