class Solution(object):
def selfDividingNumbers(self, left, right):
"""
:type left: int
:type right: int
:rtype: List[int]
"""
output = []
for i in range(left,right+1):
if i<10:
output.append(i)
elif 10<=i<100:
ge = i%10
shi = i//10
sign = (ge != 0)
if sign and i%ge==0 and i%shi==0:
output.append(i)
elif 100<=i<1000:
ge = i % 10
shi = (i // 10)%10
bai = i // 100
sign = (ge!=0)and(shi!=0)
if sign and i % ge == 0 and i % shi == 0 and i % bai == 0:
output.append(i)
elif 1000<=i<10000:
ge = i % 10
shi = (i // 10) % 10
bai = (i // 100) % 10
qian = i//1000
sign = (ge != 0) and (shi != 0) and (bai != 0)
if sign and i % ge == 0 and i % shi == 0 and i % bai == 0 and i % qian == 0:
output.append(i)
return output
leetcode 728. Self Dividing Numbers
最新推荐文章于 2023-02-25 23:03:36 发布