-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path728_SelfDividingNumbers.py
More file actions
41 lines (34 loc) · 1.11 KB
/
728_SelfDividingNumbers.py
File metadata and controls
41 lines (34 loc) · 1.11 KB
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
38
39
40
41
class Solution:
def selfDividingNumbers(self, left, right):
"""
:type left: int
:type right: int
:rtype: List[int]
"""
def isDividing(n):
for d in str(n):
if d == '0' or n % int(d) > 0:
return False
return True
ans = []
for n in range(left, right + 1):
if isDividing(n):
ans.append(n)
return ans
# ansList = []
# number = None
# remainder = None
# while left <= right:
# isSelfDividing = True
# number = left
# while number != 0 or isSelfDividing:
# remainder = number % 10
# isSelfDividing = remainder != 0 or left % remainder == 0
# number /= 10
# if isSelfDividing:
# ansList.append(left)
# left += 1
# return ansList
if __name__ == '__main__':
solution = Solution()
print (solution.selfDividingNumbers(1,22))