g0301_0400.s0326_power_of_three.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
package g0301_0400.s0326_power_of_three;
// #Easy #Top_Interview_Questions #Math #Recursion
public class Solution {
// regular method that has a loop
public boolean isPowerOfThree(int n) {
if (n < 3 && n != 1) {
return false;
}
while (n != 1) {
if (n % 3 != 0) {
return false;
}
n /= 3;
}
return true;
}
}