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 == 0128 % 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的更多相关文章

  1. [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 ...

  2. 【Leetcode_easy】728. Self Dividing Numbers

    problem 728. Self Dividing Numbers solution1: 使用string类型来表示每位上的数字: class Solution { public: vector&l ...

  3. 【LeetCode】728. Self Dividing Numbers 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 循环 filter函数 数字迭代 日期 题目地址:h ...

  4. Python 解leetcode:728. Self Dividing Numbers

    思路:循环最小值到最大值,对于每一个值,判断每一位是否能被该值整除即可,思路比较简单. class Solution(object): def selfDividingNumbers(self, le ...

  5. LeetCode 728 Self Dividing Numbers 解题报告

    题目要求 A self-dividing number is a number that is divisible by every digit it contains. For example, 1 ...

  6. LeetCode - 728. Self Dividing Numbers

    A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...

  7. [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. ...

  8. [LeetCode&Python] Problem 1: Two Sum

    Problem Description: Given an array of integers, return indices of the two numbers such that they ad ...

  9. [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 ...

随机推荐

  1. MongoDB(课时14 正则运算)

    3.2.4.9 正则运算 如果想实现模糊查询,必须使用正则表达式,而且正则表达式使用的语言是Perl兼容的正则表达式的形式. 要实现正则使用,则按照如下的定义格式: 基础语法:{key : 正则标记} ...

  2. STL_算法_05_集合算法

    ◆ 常用的集合算法: 1. 1.1.第6讲 PPT.40 ◆ set_union() :  构造一个有序序列,包含两个有序序列的并集. 1.2.第6讲 PPT.40 ◆ set_intersectio ...

  3. typescripts学习

    可选与默认参数 可选参数:在参数名后面,冒号前面添加一个问号,则表明该参数是可选的.如下代码: function buildName(firstName: string, lastName?: str ...

  4. hdu-4289 最大流Dinic模板题

    拆点,套模板. 详情见代码. // // main.cpp // hdu_4289 // // Created by Luke on 16/8/29. // Copyright © 2016年 Luk ...

  5. android--------ListView和ExpandableListView的侧滑删除操作

    本案例主要实现了ListView和ExpandableListView的侧滑删除操作功能 效果图: ListView的Adapter类 private class SlideAdapter exten ...

  6. Python基础--文件操作和集合

    这篇博客来说一下python对文件的操作. 对文件的操作分三步: 1.打开文件获取文件的句柄,句柄就理解为这个文件 2.通过文件句柄操作文件 3.关闭文件. 现有以下文件file.txt: 我们哭了 ...

  7. 使用python创建mxnet操作符(网络层)

    对cuda了解不多,所以使用python创建新的操作层是个不错的选择,当然这个性能不如cuda编写的代码. 在MXNET源码的example/numpy-ops/下有官方提供的使用python编写新操 ...

  8. 【转】C# 中使用 ThoughtWorks.QRCode.dll 生成指定尺寸和边框宽度的二维码

    本文介绍在 C# 中使用 ThoughtWorks.QRCode.dll 生成指定尺寸和边框宽度的二维码.网上文章大多只是简单介绍内置参数的设置,根据我的使用目的,增加了自定义目标二维码图片尺寸和白边 ...

  9. FZU 2124 吃豆人 bfs

    题目链接:吃豆人 比赛的时候写的bfs,纠结要不要有vis数组设置已被访问,没有的话死循环,有的话就不一定是最优解了.[此时先到的不一定就是时间最短的.]于是换dfs,WA. 赛后写了个炒鸡聪明的df ...

  10. HDU 1934 特殊数字

    有两种车牌号.让你判断第二种是不是在第一种之后且在第一种出Kth之前的车牌号. 本解中是把前面的字母看成一位十进制的数.自己是一个26或者21进制的数.如果比较时有两种.那么第一种和第一种的最后一个比 ...