Class Solution

java.lang.Object
g0301_0400.s0326_power_of_three.Solution

public class Solution extends Object
326 - Power of Three.<p>Easy</p> <p>Given an integer <code>n</code>, return <em><code>true</code> if it is a power of three. Otherwise, return <code>false</code></em>.</p> <p>An integer <code>n</code> is a power of three, if there exists an integer <code>x</code> such that <code>n == 3<sup>x</sup></code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 27</p> <p><strong>Output:</strong> true</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 0</p> <p><strong>Output:</strong> false</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> n = 9</p> <p><strong>Output:</strong> true</p> <p><strong>Constraints:</strong></p> <ul> <li><code>-2<sup>31</sup> <= n <= 2<sup>31</sup> - 1</code></li> </ul> <p><strong>Follow up:</strong> Could you solve it without loops/recursion?</p>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isPowerOfThree

      public boolean isPowerOfThree(int n)