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. 【大数据系列】apache hive 官方文档翻译

    GettingStarted 开始 Created by Confluence Administrator, last modified by Lefty Leverenz on Jun 15, 20 ...

  2. Webpack2 升级指南和特性摘要(转)

    Webpack2 升级指南和特性摘要 resolve.root, resolve.fallback, resolve.modulesDirectories 上述三个选项将被合并为一个标准配置项:res ...

  3. Calling a Java Method from Native Code

    http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html Calling Java Method ...

  4. Elasticsearch学习之深入聚合分析一---基本概念

    首先明白两个核心概念:bucket和metric 1. bucket:一个数据分组 city name 北京 小李 北京 小王 上海 小张 上海 小丽 上海 小陈 基于city划分buckets,划分 ...

  5. 你可能不知道的shell、bash二三事(Centos 7)

    个人.bashrc: ~/.bashrc: # .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp ...

  6. 以太网端口二种链路类型:Access 和Trunk

    Access 类型的端口:只能属于1 个VLAN,一般用于连接计算机的端口:    Trunk 类型的端口:可以允许多个VLAN 通过,可以接收和发送多个VLAN 的报文,一般用于交换机之间连接的端口 ...

  7. 关于linux例行任务crontab的使用

    Linux 例行性任务(也叫周期性任务)命令使用:crontab1.crontab -l   查看当前用户的任务2.crontab -e  编辑(设置)当前用户的任务,执行行不用重启crond服务.3 ...

  8. Sciter TIScript KeyEvent

    function movable() // install movable window handler{ function onKeyDown(evt) { if(evt.keyCode == Ev ...

  9. 如何通过python代码解压zip包

    转载至https://www.cnblogs.com/flyhigh1860/p/3884842.html 很多人在Google上不停的找合适自己的压缩,殊不知Py的压缩很不错.可以试试.当然C#,J ...

  10. DevOps之持续交付

    持续交付 持续交付是一种可以帮助团队以更短的周期交付软件的方法,该方法确保了团队可以在任何时间发布出可靠的软件.该方法意在以更快速度更高频率进行软件的构建.测试和发布. 通过对生产环境中的应用程序进行 ...