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.

思路就是一次判断, 然后用一个helper function去判断是否为self-divisible的数即可.

Code

class Solution(object):
def selfDividingNumbers(self, left, right):
## Solution, basic T:O(n lg(right)) , but we know max(right) = 10000, then T: O(n)
def helper(n):
for c in str(n):
if c == '' or n%int(c):
return False
return True
ans = []
for i in range(left, right + 1):
if helper(i):
ans.append(i)
return ans

[LeetCode] 728. Self Dividing Numbers_Easy tag: Math的更多相关文章

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

  2. LeetCode 728 Self Dividing Numbers 解题报告

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

  3. [LeetCode] 492. Construct the Rectangle_Easy tag: Math

    For a web developer, it is very important to know how to design a web page's size. So, given a speci ...

  4. [LeetCode] 598. Range Addition II_Easy tag: Math

    做个基本思路可以用 brute force, 但时间复杂度较高. 因为起始值都为0, 所以肯定是左上角的重合的最小的长方形就是结果, 所以我们求x, y 的最小值, 最后返回x*y. Code    ...

  5. [LeetCode] 367. Valid Perfect Square_Easy tag:Math

    Given a positive integer num, write a function which returns True if num is a perfect square else Fa ...

  6. [LeetCode] 172. Factorial Trailing Zeroes_Easy tag: Math

    Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...

  7. [LeetCode] 193. Valid Phone Numbers_Easy tag: Bash

    Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...

  8. [LeetCode] 64. Minimum Path Sum_Medium tag: Dynamic Programming

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  9. 【Leetcode_easy】728. Self Dividing Numbers

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

随机推荐

  1. vue案例 - v-model实现自定义样式の多选与单选

    接,上文:https://www.cnblogs.com/padding1015/p/9265985.html 这两天在玩mpvue,但是下午如果对着文档大眼瞪小眼的话,肯定会睡着的. 想起昨晚的fl ...

  2. 原生js--元素尺寸、位置和溢出

    判断元素尺寸和位置的方法: elem.getBoundingClientRect()  // 已验证IE7+.firefox.chrome均支持此方法 该方法返回一个对象(坐标值为视口坐标,不是文档坐 ...

  3. Sencha Touch 实战开发培训 视频教程 第二期 第四节

    2014.4.14 晚上8:10分开课. 本节课耗时没有超出一个小时,主要讲解了list的一些扩展用法. 本期培训一共八节,前两节免费,后面的课程需要付费才可以观看. 本节内容: List的高级应用 ...

  4. XmlSerializer的GenerateTempAssembly性能问题例外

    XmlSerializer的两个构造函数不会出现每次构造都创建TempAssembly的性能问题,其内部做了缓存. public XmlSerializer(Type type) public Xml ...

  5. mongodb的远程访问

    1,centos6上安装mongodb:2,新建可以远程访问的用户,以便可以远程访问: [root@localhost ~]# cd /usr/local/mongodb/bin/ [root@loc ...

  6. 【咸鱼教程】TextureMerger1.6.6 二:Sprite Sheet的制作和使用

    Sprite Sheet主要用于将零碎的小图合并成一张整图.减少加载图片时http的请求次数. 1 打开TextureMerger,选择Sprite Sheet 2  添加纹理(未创建项目时,会先弹出 ...

  7. python pytest测试框架介绍一

    一.安装 pytest不是python默认的package,需要自动手工安装. pytest支持python 2.6--3.5之间的版本,同时可以在unix及windows上安装 安装方式: pip ...

  8. #if 和 #ifdef 条件编译注意

    之前写程序很少用到这两个条件编译,只是在头文件的开头使用过 #ifdef ....<CODE>....  #endif,他是防止头文件被重复包含,导致的变量被多处声明或定义. 最近写程序发 ...

  9. 静态类(static)与java值传递、引用传递小测

    java中都是值传递.直接上代码了: class TestStaticA { static { System.out.println("b"); } public TestStat ...

  10. 密码强度demo(弱中强)

    <!doctype html> <html> <head> <script src="http://ajax.microsoft.com/ajax/ ...