本题注意点:整除用//
import numpy as np
def selfDividingNumbers(left, right):
"""
:type left: int
:type right: int
:rtype: List[int]
"""
def self_divided(x):
t = []
y = x
while(y != 0):
t.append(y%10)
y //= 10
for i in t:
if i == 0: return False
elif x % i != 0: return False
return True
ans = []
for x in range(left, right+1):
if self_divided(x):
ans.append(x)
return ans
# sample:
left, right = 1, 22
print(selfDividingNumbers(left, right))