LeetCode 728. 自除数 Python
2018-09-10 14:25
302 查看
自除数 是指可以被它包含的每一位数除尽的数。
例如,128 是一个自除数,因为
128 % 1 == 0,
128 % 2 == 0,
128 % 8 == 0。
还有,自除数不允许包含 0 。
给定上边界和下边界数字,输出一个列表,列表的元素是边界(含边界)内所有的自除数。
示例 1:
输入: 上边界left = 1, 下边界right = 22 输出: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
注意:
- 每个输入参数的边界满足
1 <= left <= right <= 10000
。
[code]class Solution: def selfDividingNumbers(self, left, right): def isdivid(num): list1 = list(str(num)) if '0' in list1: return False for item in list1: if num % int(item) != 0: return False return True if left > right: return [] res = [] for i in range(left,right+1): if isdivid(i): res.append(i) return res
阅读更多
相关文章推荐
- 58. Length of Last Word Leetcode Python
- [置顶] LeetCode--Minimum Path Sum (最小路径和)Python
- Leetcode 079 搜索单词 Python C++ 史上最详细题解系列
- [LeetCode]题解(python):004-Median of Two Sorted Arrays
- leetcode python - addTwoNumbers
- Python解LeetCode 131: Palindrome Partitioning(Python中的浅复制与深复制)
- 【Leetcode】【python】Maximum Depth of Binary Tree
- [Leetcode.python] 002. Add Two Numbers
- Leetcode-Roman to Integer-Python
- [Leetcode] 15.3Sum @python
- 【LeetCode】【Python】Sort Colors
- LeetCode 69 — Sqrt(x)(C++ Java Python)
- Leetcode_word-break(c++ and python version)
- [Leetcode][python]Construct Binary Tree from Preorder and Inorder Traversal (Inorder and Postorder)
- 32. Longest Valid Parentheses leetcode python new season 2016
- leetcode:Single Number【Python版】
- LeetCode 149 — Max Points on a Line(C++ Java Python)
- leetcode python 100st
- LeetCode 105,106. Construct Binary Tree 重建二叉树 Python Solution
- [leetcode: Python]437.Path Sum 3