Problem statement

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

Solution

Literally, do what is asked: check every number in given range.

Complexity

Time complexity is O((R - L) * log R), where L and R are our left and right. Space complexity is O(R - L).

Code

class Solution:
    def selfDividingNumbers(self, left, right):
        out = []
        for i in range(left, right + 1):
            if all(s != "0" and i % int(s) == 0 for s in str(i)):
                out += [i]
        return out