Given an integer n, return true if it is a power of four. Otherwise, return false.
A number is a power of four if there exists an integer x such that n === 4^x.
Examples
Input: n = 1
Output: true
Explanation: 4^0 = 1
Input: n = 16
Output: true
Explanation: 4^2 = 16
Input: n = 8
Output: false
Explanation: 8 is not a power of 4
Input: n = 0
Output: false
Explanation: 0 is not a power of 4
Constraints
- (-2^{31} \leq n \leq 2^{31} - 1)
- Return
false for:
Function Signature
function isPowerOfFour(n) {
// Your code here
}
Test Cases
Base cases:
Powers of 4:
n = 16
n = 64
n = 256
n = 1024
Non-powers:
n = 2
n = 8
n = 32
n = 100
Edge cases:
Large numbers: