Skip to content

Commit 6bbb76c

Browse files
Create 0728. Self Dividing Numbers.py
1 parent 37e2116 commit 6bbb76c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

0728. Self Dividing Numbers.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#Runtime: 40 ms, faster than 92.72% of Python3 online submissions for Self Dividing Numbers.
2+
#Memory Usage: 14.4 MB, less than 30.16% of Python3 online submissions for Self Dividing Numbers.
3+
4+
class Solution:
5+
def selfDividingNumbers(self, left: int, right: int) -> List[int]:
6+
if right < 10:
7+
return [i for i in range(left, right + 1)]
8+
cand = []
9+
for i in range(left, right + 1):
10+
divisor = set(str(i))
11+
if '0' not in divisor:
12+
divisible = True
13+
for j in divisor:
14+
if i%int(j) != 0:
15+
divisible = False
16+
break
17+
if divisible == True:
18+
cand.append(i)
19+
return cand
20+

0 commit comments

Comments
 (0)