326. Power of Three Easy
1/**
2 * [326] Power of Three
3 *
4 * Given an integer n, return true if it is a power of three. Otherwise, return false.
5 * An integer n is a power of three, if there exists an integer x such that n == 3^x.
6 *
7 * Example 1:
8 *
9 * Input: n = 27
10 * Output: true
11 * Explanation: 27 = 3^3
12 *
13 * Example 2:
14 *
15 * Input: n = 0
16 * Output: false
17 * Explanation: There is no x where 3^x = 0.
18 *
19 * Example 3:
20 *
21 * Input: n = -1
22 * Output: false
23 * Explanation: There is no x where 3^x = (-1).
24 *
25 *
26 * Constraints:
27 *
28 * -2^31 <= n <= 2^31 - 1
29 *
30 *
31 * Follow up: Could you solve it without loops/recursion?
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/power-of-three/
36// discuss: https://leetcode.com/problems/power-of-three/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn is_power_of_three(n: i32) -> bool {
42 false
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_326() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.