-
Notifications
You must be signed in to change notification settings - Fork 1
/
let728.py
35 lines (30 loc) · 948 Bytes
/
let728.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
# 728. Self Dividing Numbers
class Solution:
def isDividingNumber(self, num):
if '0' in str(num):
return False
else:
return 0 == sum(num%int(i) for i in str(num))
def selfDividingNumbers(self, left, right):
"""
:type left: int
:type right: int
:rtype: List[int]
"""
list =[]
for item in range(left,right+1,1):
if self.isDividingNumber(item):
list.append(item)
return list
def selfDividingNumbers2(self, left, right):
"""
:type left: int
:type right: int
:rtype: List[int]
"""
is_self_dividing = lambda num: '0' not in str(num) and all([num % int(digit) == 0 for digit in str(num)])
x = filter(is_self_dividing, range(left, right + 1))
return list(x)
a = Solution()
print(a.selfDividingNumbers(1,22))
print(a.selfDividingNumbers2(1,22))