aboutsummaryrefslogtreecommitdiff
path: root/power_of_four.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-08-15 08:33:19 +0200
committerJack Sangdahl <[email protected]>2025-08-15 08:33:19 +0200
commitf035e4f04939219d5979f67d9e36b307a60d15fb (patch)
treeedeb5fee7f6c229ee0b84c3cf1f7741ec6841f9e /power_of_four.py
parent3ae87fe80a3a60df750acefceff38c4ab09a9a30 (diff)
downloadleetcode-f035e4f04939219d5979f67d9e36b307a60d15fb.tar.gz
leetcode-f035e4f04939219d5979f67d9e36b307a60d15fb.zip
342. power of four
Diffstat (limited to 'power_of_four.py')
-rw-r--r--power_of_four.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/power_of_four.py b/power_of_four.py
index 13a0dc5..da9ab09 100644
--- a/power_of_four.py
+++ b/power_of_four.py
@@ -9,7 +9,7 @@ return 'false'. an integer 'n' is a power of four if there exists an integer
class Solution(object):
def isPowerOfFour(self, n):
- return n != 0 and n & (n - 1) == 0 and n & 1431655765 == n
+ return n > 0 and n.bit_count() == 1 and (n - 1) % 3 == 0
if __name__ == "__main__":