Description
Given an integer n, return true if it is a power of three. A number is a power of three if it can be expressed as 3^k for some non-negative integer k. Otherwise, return false.
Examples
Input:
n = 27Output:
trueExplanation:
27 = 3³.
Input:
n = 0Output:
falseExplanation:
0 is not a power of three. Powers of three are 1, 3, 9, 27, ...
Input:
n = 9Output:
trueExplanation:
9 = 3^2, which is a power of three.
Input:
n = 45Output:
falseExplanation:
45 = 9 * 5. Since 5 is not a power of 3, 45 is not a power of three.
Constraints
- •
-2³¹ ≤ n ≤ 2³¹ - 1