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
The newest version!
package g0301_0400.s0326_power_of_three;
// #Easy #Math #Recursion #2022_07_09_Time_18_ms_(85.35%)_Space_47.9_MB_(14.68%)
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;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy