Skip to content

Commit cbde2bb

Browse files
committed
isPowerOfThree - AC
1 parent c2c2c2b commit cbde2bb

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

leecode/3的幂/isPowerOfThree.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/python3
2+
# -*- coding: utf-8 -*-
3+
'''
4+
AC
5+
'''
6+
7+
import time
8+
from math import *
9+
10+
class Solution:
11+
def isPowerOfThree(self, n):
12+
"""
13+
:type n: int
14+
:rtype: bool
15+
"""
16+
if n < 1:
17+
return False
18+
return pow(3,round(log(n,3)))==n
19+
20+
21+
22+
23+
if __name__ == "__main__":
24+
25+
t0 = time.perf_counter()
26+
testlist=[243,1162261466]
27+
test=Solution()
28+
for i in testlist:
29+
print(test.isPowerOfThree(i))
30+
31+
print(time.perf_counter() - t0)
32+
33+
34+
'''
35+
class Solution:
36+
def isPowerOfThree(self, n):
37+
"""
38+
:type n: int
39+
:rtype: bool
40+
"""
41+
if n < 1:
42+
return False
43+
while (n % 3) == 0:
44+
n //= 3
45+
return n == 1
46+
'''

0 commit comments

Comments
 (0)