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
本文分享了一道LeetCode上的算法题——自除数,使用Python语言进行解答。通过判断一个数是否能被其每一位数字整除,筛选出自除数,并给出详细实现代码。
1245

被折叠的 条评论
为什么被折叠?



