java.lang.Object
g1701_1800.s1780_check_if_number_is_a_sum_of_powers_of_three.Solution

public class Solution extends Object
1780 - Check if Number is a Sum of Powers of Three.<p>Medium</p> <p>Given an integer <code>n</code>, return <code>true</code> <em>if it is possible to represent</em> <code>n</code> <em>as the sum of distinct powers of three.</em> Otherwise, return <code>false</code>.</p> <p>An integer <code>y</code> is a power of three if there exists an integer <code>x</code> such that <code>y == 3<sup>x</sup></code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 12</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> 12 = 3<sup>1</sup> + 3<sup>2</sup></p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 91</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> 91 = 3<sup>0</sup> + 3<sup>2</sup> + 3<sup>4</sup></p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 21</p> <p><strong>Output:</strong> false</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 10<sup>7</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • checkPowersOfThree

      public boolean checkPowersOfThree(int n)