Skip to content

Commit 54f7484

Browse files

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

solutions/power-of-three.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
326. Power of Three
3+
- https://leetcode.com/problems/power-of-three/
4+
- https://leetcode.com/explore/featured/card/april-leetcoding-challenge-2021/596/week-4-april-22nd-april-28th/3722/
5+
"""
6+
7+
# Method 1
8+
class Solution(object):
9+
def isPowerOfThree(self, n):
10+
"""
11+
:type n: int
12+
:rtype: bool
13+
"""
14+
if n == 0 or n == 2:
15+
return False
16+
while n:
17+
if n == 1:
18+
break
19+
if n % 3 != 0:
20+
return False
21+
n = n // 3
22+
return True

0 commit comments

Comments
 (0)