We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b47b1fc commit d2f5f9eCopy full SHA for d2f5f9e
Python/check-if-the-number-is-fascinating.py
@@ -0,0 +1,33 @@
1
+# Time: O(logn)
2
+# Space: O(1)
3
+
4
+# string, bitmask
5
+class Solution(object):
6
+ def isFascinating(self, n):
7
+ """
8
+ :type n: int
9
+ :rtype: bool
10
11
+ lookup = [0]
12
+ def check(x):
13
+ while x:
14
+ x, d = divmod(x, 10)
15
+ if d == 0 or lookup[0]&(1<<d):
16
+ return False
17
+ lookup[0] |= (1<<d)
18
+ return True
19
20
+ return check(n) and check(2*n) and check(3*n)
21
22
23
24
+# Space: O(logn)
25
+# string
26
+class Solution2(object):
27
28
29
30
31
32
+ s = str(n)+str(2*n)+str(3*n)
33
+ return '0' not in s and len(s) == 9 and len(set(s)) == 9
0 commit comments