One line Python


  • 0

    One line brute force version. Basically just check every digit d of num. Keep in mind that every dight d mustn't be zero.

    class Solution(object):
        def selfDividingNumbers(self, left, right):
            """
            :type left: int
            :type right: int
            :rtype: List[int]
            """
            return [num for num in range(left, right+1) if all((int(d) and not num % int(d)) for d in str(num))]
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.