#326
Easy Algorithms Power of three
Math Recursion
50.7% acceptance
Jan 12, 2026
3696
316
Given an integer n, return true if it is a power of three. Otherwise, return false.
An integer n is a power of three, if there exists an integer x such that n == 3x.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn is_power_of_three(n: i32) -> bool {
n > 0 && 1162261467 % n == 0
}
}