-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
728.py
37 lines (37 loc) · 1.37 KB
/
728.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
__________________________________________________________________________________________________
sample 36 ms submission
class Solution:
def selfDividingNumbers(self, left, right):
nums = []
for n in range(left, right+1):
if 1<=n<10:
nums.append(n)
else:
is_divide = True
nn = n
while n > 0:
if n%10 == 0 or nn % (n%10) != 0:
is_divide = False
break
n //= 10
if is_divide:
nums.append(nn)
return nums
__________________________________________________________________________________________________
sample 12944 kb submission
class Solution:
def selfDividingNumbers(self, left: int, right: int) -> List[int]:
ans = []
for i in range(left, right + 1):
shift = i
is_self_dividing = True
while(shift != 0):
ones_digit = shift % 10
if ones_digit == 0 or i % ones_digit != 0:
is_self_dividing = False
break
shift = (shift - ones_digit) // 10
if is_self_dividing:
ans.append(i)
return ans
__________________________________________________________________________________________________