Power of Three - Problem
Given an integer n, return true if it is a power of three. Otherwise, return false.
An integer n is a power of three, if there exists an integer x such that n == 3^x.
Input & Output
Example 1 — Perfect Power of Three
$
Input:
n = 27
›
Output:
true
💡 Note:
27 = 3³, so it is a power of three
Example 2 — Not a Power of Three
$
Input:
n = 0
›
Output:
false
💡 Note:
0 is not a power of three (powers of 3 are positive)
Example 3 — Base Case
$
Input:
n = 1
›
Output:
true
💡 Note:
1 = 3⁰, so it is a power of three
Constraints
- -2³¹ ≤ n ≤ 2³¹ - 1
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given integer n to check
2
Process
Apply mathematical test for power of 3
3
Output
Return true if n = 3^x for some integer x
Key Takeaway
🎯 Key Insight: Use mathematical properties like integer limitations or logarithms for efficient checking
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code