Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions quizzes/_342.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Question: Power of Four
Desc: Given an integer n, return True if it is a power of four.
Otherwise, return False.
An integer n is a power of four if there exists an integer x
such that n == 4^x.
URL: https://leetcode.com/problems/power-of-four/
Resource: Runtime: 28 ms, Memory Usage: 16.5 MB
"""
class Solution:
def isPowerOfFour(self, n: int) -> bool:
# A number is power of four if:
# 1. It's greater than 0
# 2. It's a power of two (n & (n-1)) == 0
# 3. The only set bit is at an even position
return n > 0 and (n & (n - 1)) == 0 and (n - 1) % 3 == 0