Python 解leetcode:728. Self Dividing Numbers

思路:循环最小值到最大值,对于每一个值,判断每一位是否能被该值整除即可,思路比较简单。

class Solution(object):
    def selfDividingNumbers(self, left, right):
        """
        :type left: int
        :type right: int
        :rtype: List[int]
        """
        ret = []
        for i in range(left, right+1):
            val = i
            flag = 1
            while i:
                remain = i % 10
                if not remain or val % remain != 0:
                    flag = 0
                    break
                i /= 10
            if flag:
                ret.append(val)
        return ret
posted @ 2017-11-24 22:08  潇湘旧友  阅读(1113)  评论(0编辑  收藏  举报