Skip to content

Commit 1729074

Browse files
committed
Do 'similar questions' to daily
1 parent 84ac47b commit 1729074

File tree

7 files changed

+32
-0
lines changed

7 files changed

+32
-0
lines changed

my-submissions/e231 v2.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def isPowerOfTwo(self, n: int) -> bool:
3+
return n > 0 and bin(n).count('1') == 1

my-submissions/e231.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def isPowerOfTwo(self, n: int) -> bool:
3+
return n >= 1 and (n == 1 or n // 2 * 2 == n and self.isPowerOfTwo(n // 2))

my-submissions/e326 v2.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def isPowerOfThree(self, n: int) -> bool:
3+
if n <= 0 :
4+
return False
5+
while n != 1 :
6+
prev = n
7+
n //= 3
8+
if n * 3 != prev :
9+
return False
10+
11+
return True

my-submissions/e326 v3.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def isPowerOfThree(self, n: int) -> bool:
3+
return n >= 1 and (n == 1 or n // 3 * 3 == n and self.isPowerOfThree(n // 3))

my-submissions/e326.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def isPowerOfThree(self, n: int) -> bool:
3+
return n > 0 and n == 3 ** int(log(n, 3) + 0.0001)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
def isPowerOfFour(self, n: int) -> bool:
3+
return n == 1 or \
4+
n > 0 and (bin(n)[2:][-2:].count('1') == 0) \
5+
and (bin(n)[-3:1:-2].count('1') == 1) \
6+
and (bin(n)[-4:1:-2].count('1') == 0)

my-submissions/e342.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def isPowerOfFour(self, n: int) -> bool:
3+
return n >= 1 and (n == 1 or n // 4 * 4 == n and self.isPowerOfFour(n // 4))

0 commit comments

Comments
 (0)