We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c2c2c2b commit cbde2bbCopy full SHA for cbde2bb
leecode/3的幂/isPowerOfThree.py
@@ -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
36
37
38
39
40
41
42
43
+ while (n % 3) == 0:
44
+ n //= 3
45
+ return n == 1
46
0 commit comments