1. 程式人生 > >leetcode 728:Self Dividing Numbers with Python

leetcode 728:Self Dividing Numbers with Python

class Solution:
    def selfDividingNumbers(self, left, right):
        """
        :type left: int
        :type right: int
        :rtype: List[int]
        """
        listres = []
        for i in range(left,right+1):
            if self.isD(i):
                listres.append(i)
                
        return listres
    def isD(self,digit):
        string = str(digit)
        list1 = list(string)
        if '0' in list1:
            return False
        else:
            for i in list1:
                j = int(i)
                if digit%j != 0:
                    return False
        return True