Facebook Pixel

Power of Three

JavaScript
easy
25 mins

Given an integer n, return true if it is a power of three. Otherwise, return false.

A number is a power of three if there exists an integer x such that n === 3^x.

Examples

Input: n = 1 Output: true Explanation: 3^0 = 1 Input: n = 9 Output: true Explanation: 3^2 = 9 Input: n = 10 Output: false Explanation: 10 is not a power of 3 Input: n = 0 Output: false Explanation: 0 is not a power of 3

Constraints

  • -2^31 ≤ n ≤ 2^31 - 1
  • Return false for:
    • n ≤ 0
    • non-integer inputs

Companies:

stripe
dropbox
spotify
infosys

Solve Similar questions 🔥

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.