leetcode 算法题 (python),从易到难,分享到博客,促进自己坚持刷题。
class Solution:
def selfDividingNumbers(self, left, right):
"""
:type left: int
:type right: int
:rtype: List[int]
"""
nums = []
a = 0
for num in range(left, right + 1):
if "0" not in str(num): #去除有0的数
for i in str(num):
if num % int(i)==0:
a = num
continue
else:
a = 0
break
nums.append(a)
while 0 in nums:
nums.remove(0)
return nums