|
| 1 | +<h2><a href="https://leetcode.com/problems/power-of-three">Power of Three</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><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> |
| 2 | + |
| 3 | +<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> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | + |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> n = 27 |
| 10 | +<strong>Output:</strong> true |
| 11 | +<strong>Explanation:</strong> 27 = 3<sup>3</sup> |
| 12 | +</pre> |
| 13 | + |
| 14 | +<p><strong class="example">Example 2:</strong></p> |
| 15 | + |
| 16 | +<pre> |
| 17 | +<strong>Input:</strong> n = 0 |
| 18 | +<strong>Output:</strong> false |
| 19 | +<strong>Explanation:</strong> There is no x where 3<sup>x</sup> = 0. |
| 20 | +</pre> |
| 21 | + |
| 22 | +<p><strong class="example">Example 3:</strong></p> |
| 23 | + |
| 24 | +<pre> |
| 25 | +<strong>Input:</strong> n = -1 |
| 26 | +<strong>Output:</strong> false |
| 27 | +<strong>Explanation:</strong> There is no x where 3<sup>x</sup> = (-1). |
| 28 | +</pre> |
| 29 | + |
| 30 | +<p> </p> |
| 31 | +<p><strong>Constraints:</strong></p> |
| 32 | + |
| 33 | +<ul> |
| 34 | + <li><code>-2<sup>31</sup> <= n <= 2<sup>31</sup> - 1</code></li> |
| 35 | +</ul> |
| 36 | + |
| 37 | +<p> </p> |
| 38 | +<strong>Follow up:</strong> Could you solve it without loops/recursion? |
0 commit comments