Given an integer n, return true if it is a power of three, meaning there is an integer x with n == 3^x. Otherwise return false. Follow up: can you solve it without loops or recursion?
Given an integer n, return true if it is a power of three, meaning there is an integer x with n == 3^x. Otherwise return false. Follow up: can you solve it without loops or recursion?
Example 1:
Input: {"n":27}
Output: true
Constraints:
−231≤n≤231−1
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":27}
The slow way: divide 27 by 3 while the remainder is 0. A power of three shrinks all the way to 1.