Simple Java Loop Solution


  • -15
    F
    public class Solution {
        public boolean isPowerOfThree(int n) {
            while(n % 3 == 0 && n > 1) {
                n = n / 3;
            }
            return n == 1;
        }
    }

Log in to reply
 

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