dsa · easy
Power of Three
Return whether n is a positive power of three (1, 3, 9, 27, …).
Arguments
n— integer to test
Example
n = 27 → true. n = 0 → false. n = 9 → true.
Constraints
-2^31 <= n <= 2^31 - 1 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 27 Expected: true
Example 2
Input: 0 Expected: false
Example 3
Input: 9 Expected: true