From 6ff8d1f1b79061c354494cb2885c0ada6a4fe4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=E1=BB=93=20V=C4=83n=20H=C3=B2a?= <56647826+hovanhoa@users.noreply.github.com> Date: Mon, 23 Oct 2023 09:42:14 +0700 Subject: [PATCH] Time: 35 ms (84.07%), Space: 16 MB (99.16%) - LeetHub --- 0342-power-of-four/0342-power-of-four.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 0342-power-of-four/0342-power-of-four.py diff --git a/0342-power-of-four/0342-power-of-four.py b/0342-power-of-four/0342-power-of-four.py new file mode 100644 index 0000000..34e02f4 --- /dev/null +++ b/0342-power-of-four/0342-power-of-four.py @@ -0,0 +1,4 @@ +class Solution: + def isPowerOfFour(self, n: int) -> bool: + mask = 0x55555555 + return n > 0 and (n & (n - 1)) == 0 and (n & mask) == n