Skip to main content

342 - Power of Four

Details

KeyValue
Linkhttps://leetcode.com/problems/power-of-four/
LanguagePython 3
Runtime31 ms, faster than 95.07% of Python3 online submissions for Power of Four
Memory Usage13.8 MB, less than 54.38% of Python3 online submissions for Power of Four
DatastructuresInt
AlgorithmsBit Manipulation
ComplexityTime: O(1) Memory: O(1)

Procedure

  1. ...

Code

class Solution:
def isPowerOfFour(self, n: int) -> bool:
return n > 0 and (n & n-1) == 0 and n & (0xAAAAAAAA) == 0