[LeetCode&Python] Problem 728. Self Dividing Numbers
A self-dividing number is a number that is divisible by every digit it contains.
For example, 128 is a self-dividing number because 128 % 1 == 0
, 128 % 2 == 0
, and 128 % 8 == 0
.
Also, a self-dividing number is not allowed to contain the digit zero.
Given a lower and upper number bound, output a list of every possible self dividing number, including the bounds if possible.
Example 1:
Input:
left = 1, right = 22
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
Note:
- The boundaries of each input argument are
1 <= left <= right <= 10000
.
Brute-Force!!!
class Solution:
def selfDividingNumbers(self, left, right):
"""
:type left: int
:type right: int
:rtype: List[int]
"""
result=[] for num in range(left, right+1):
strnum=str(num) flag=True for digit in strnum:
if digit=='0':
flag=False
break if num%int(digit) !=0:
flag=False
break if flag:
result.append(num) return result
[LeetCode&Python] Problem 728. Self Dividing Numbers的更多相关文章
- [LeetCode&Python] Problem 448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
- 【Leetcode_easy】728. Self Dividing Numbers
problem 728. Self Dividing Numbers solution1: 使用string类型来表示每位上的数字: class Solution { public: vector&l ...
- 【LeetCode】728. Self Dividing Numbers 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 循环 filter函数 数字迭代 日期 题目地址:h ...
- Python 解leetcode:728. Self Dividing Numbers
思路:循环最小值到最大值,对于每一个值,判断每一位是否能被该值整除即可,思路比较简单. class Solution(object): def selfDividingNumbers(self, le ...
- LeetCode 728 Self Dividing Numbers 解题报告
题目要求 A self-dividing number is a number that is divisible by every digit it contains. For example, 1 ...
- LeetCode - 728. Self Dividing Numbers
A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...
- [LeetCode&Python] Problem 628. Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- [LeetCode&Python] Problem 1: Two Sum
Problem Description: Given an array of integers, return indices of the two numbers such that they ad ...
- [LeetCode&Python] Problem 118. Pascal's Triangle
Given a non-negative integer numRows, generate the first numRows of Pascal's triangle. In Pascal's t ...
随机推荐
- a 样式重置 常见用法
样式重置 a:link, a:visited, a:hover, a:active{ color: #fff; text-decoration: none; } 常见用法 ( rel=& ...
- Lua中Table的学习
--table 是 Lua 的一种数据结构,用来帮助我们创建不同的数据类型,如:数组.字典等 --Lua也是通过table来解决模块(module).包(package)和对象(Object)的. 例 ...
- eclipse jsp:useBean搞死人了。
eclipse jsp:useBean搞死人了 首页,用eclipse需要经常重启tomcat服务器,这是因为你编辑了页面正浏览这个页面,而这个页面还处在之前的错误编译中... 其次,第一次用到use ...
- PHP函数总结 (五)
<?php /** * 回调函数: * 指调用函数时并不是传递一个标准的变量作为参数,而是将另一个函数作为参数传递到调用的函数中 * 使用回调函数可以 将一段自己定义的功能传到函数内部使用 * ...
- hdu 6299 Balanced Sequence (括号序列,贪心)
大意: 记$f(t)$表示字符串$t$的最长括号匹配子序列, 给定n个括号序列, 求它们重排后的最大f(t). 首先可以注意到一个括号序列中已经匹配的可以直接消去, 一定不会影响最优解. 那么这样最终 ...
- 『Numpy』高级函数_np.nditer()&ufunc运算
1.np.nditer():numpy迭代器 默认情况下,nditer将视待迭代遍历的数组为只读对象(read-only),为了在遍历数组的同时,实现对数组元素值得修改,必须指定op_flags=[' ...
- VS2013/2015 html 设计视图窗口
- HashMap相关(二)
基于哈希表的 Map 接口的实现.此实现提供所有可选的映射操作,并允许使用 null 值和 null 键.(除了不同步和允许使用 null 之外, HashMap 类与 Hashtable 大致相同. ...
- currentSession
public class HibernateUtil { public static final ThreadLocal session =new ThreadLocal(); public ...
- 李阳音标速成MP3文本
第一节:前元音 No. 1 [i:]穿针引线长衣音,简称"长衣音" 字母:e字母:ee 字母:ea字母:ie字母:ei 其发音要领是发音时舌尖抵下齿,前舌尽量抬高.舌位高于/i/: ...