Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Power of Three

XPChallenge Points: 10
levelLevel: Easy

Given an integer n, determine whether it belongs to the sequence of numbers formed by repeatedly multiplying 3 (i.e., 1, 3, 9, 27, 81, …).
Return true if n can be represented as 3^x for some integer x.
Otherwise, return false.

A valid power of three must be positive and must exactly match some exponent of 3.

Example 1:

Input: n = 81

Output: true

Explanation:

81 is equal to 3⁴.

Example 2:

Input: n = 10

Output: false

Explanation:

10 is not any power of 3.

Example 3:

Input: n = 1

Output: true

Explanation:

1 = 3⁰.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result