1780. Check if Number is a Sum of Powers of Three Medium
1/**
2 * [1780] Check if Number is a Sum of Powers of Three
3 *
4 * Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false.
5 * An integer y is a power of three if there exists an integer x such that y == 3^x.
6 *
7 * Example 1:
8 *
9 * Input: n = 12
10 * Output: true
11 * Explanation: 12 = 3^1 + 3^2
12 *
13 * Example 2:
14 *
15 * Input: n = 91
16 * Output: true
17 * Explanation: 91 = 3^0 + 3^2 + 3^4
18 *
19 * Example 3:
20 *
21 * Input: n = 21
22 * Output: false
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= n <= 10^7
28 *
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/
33// discuss: https://leetcode.com/problems/check-if-number-is-a-sum-of-powers-of-three/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38 pub fn check_powers_of_three(n: i32) -> bool {
39 false
40 }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_1780() {
51 }
52}
53
Back
© 2025 bowen.ge All Rights Reserved.