Skip to content

Commit 9ee6114

Browse files
authored
Create check-if-number-is-a-sum-of-powers-of-three.py
1 parent e2c5b6c commit 9ee6114

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Time: O(logn)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def checkPowersOfThree(self, n):
6+
"""
7+
:type n: int
8+
:rtype: bool
9+
"""
10+
while n > 0:
11+
if n%3 == 2:
12+
return False
13+
n //= 3
14+
return True

0 commit comments

Comments
 (0)