Leetcode 728 Solution

This article provides solution to leetcode question 728 (self-dividing-numbers)

https://leetcode.com/problems/self-dividing-numbers

Solution

class Solution:
    def selfDividingNumbers(self, left: int, right: int) -> List[int]:
        ans = []
        for i in range(left, right + 1):
            j = i

            while j:
                d = j % 10
                if d == 0:
                    break
                if i % d != 0:
                    break
                j //= 10

            if j == 0:
                ans.append(i)

        return ans