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
falsefor:- n ≤ 0
- non-integer inputs
Companies:
stripe
dropbox
spotify
infosys
Solve Similar questions 🔥
Want to upskill? Explore our courses!
Namaste DSA
Master DSA from scratch with numerous problems, and expert guidance.
Namaste React
Wanna dive deep into React and become Frontend Expert? Learn with me now!
Namaste Frontend System Design
The most comprehensive and detailed course for frontend system design.
Namaste Node.js
Wanna dive deep into Node.js? Enroll into `Namaste Node.js` now!
