题目要求

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

题目分析及思路

题目给出一个整数范围,要求输出该范围中的所有self-dividing number(包含边界数字)。该数字的特点是能被它所包含的所有整数整除且不包含零。可以遍历范围内的所有数字,对每个数字进行判断,符合要求的推进返回的列表中。判断条件的设置使用循环的方式,循环终止的条件应当是每次取余得一位数,那一位数为零则判断停止,循环内部拿到那一位数后对整体数字进行取余,若不为零同样跳出循环。出循环后通过判断剩下的位数的数字是否空了,若空了则说明符合条件,推入返回列表,否则不满足。

python代码​

class Solution:

def selfDividingNumbers(self, left, right):

"""

:type left: int

:type right: int

:rtype: List[int]

"""

res = []

for i in range(left,right + 1):

temp = i

while(temp % 10):

if i % (temp % 10) != 0:

break

temp //= 10

if temp == 0:

res.append(i)

return res

LeetCode 728 Self Dividing Numbers 解题报告的更多相关文章

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

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

  2. 【LeetCode】386. Lexicographical Numbers 解题报告(Python)

    [LeetCode]386. Lexicographical Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  3. LeetCode - 728. Self Dividing Numbers

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

  4. LeetCode 2. Add Two Numbers 解题报告

    题意: 有两个链表,它们表示逆序的两个非负数.例 (2 -> 4 -> 3)表示342,求两个数字的和,并用同样的方式逆序输出.如342+465 = 807,你需要把结果表达为(7 -&g ...

  5. 【LeetCode】129. Sum Root to Leaf Numbers 解题报告(Python)

    [LeetCode]129. Sum Root to Leaf Numbers 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/pr ...

  6. 【LeetCode】165. Compare Version Numbers 解题报告(Python)

    [LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  7. LeetCode 2 Add Two Sum 解题报告

    LeetCode 2 Add Two Sum 解题报告 LeetCode第二题 Add Two Sum 首先我们看题目要求: You are given two linked lists repres ...

  8. 【LeetCode】376. Wiggle Subsequence 解题报告(Python)

    [LeetCode]376. Wiggle Subsequence 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.c ...

  9. 【LeetCode】91. Decode Ways 解题报告(Python)

    [LeetCode]91. Decode Ways 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...

随机推荐

  1. Adam算法

    结合了Momentum 和RMSprop算法的优点

  2. hdoj:2044

    #include <iostream> using namespace std; long long fib(int n) { ; ; ) ; ) { long long f2 = f0 ...

  3. 【css】zSass - 用 sass 编写 css

    zSass 是自己整理的一个 sass 库,参考了 sassCore. 目录结构 variables.scss 默认值设置. reset.scss 重置浏览器样式.(参考:normalize) com ...

  4. C# 内存理论与实践

    The C# Memory Model in Theory and Practice Best Practices All code you write should rely only on the ...

  5. 教程:Spagobi开源BI系统 Console报表设计教程

    Console Designer 1 Console Designer Console Designer 1.1 Introduction 1.2 Dataset Tab 1.3 Summary Pa ...

  6. highCharts图表入门简介

    一.Highcharts简介 Highcharts:功能强大.开源.美观.图表丰富.兼容绝大多数浏览器的纯js图表库 Highcharts是一款纯javascript编写的图表库,能够很简单便捷的在W ...

  7. mysql 第二高薪水

    编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | ...

  8. 给 Advice 传递参数

    参数绑定是在下面这个方法中做的:org.springframework.aop.aspectj.AbstractAspectJAdvice#invokeAdviceMethod(JoinPoint j ...

  9. 网络编程 -- RPC实现原理 -- NIO多线程 -- 迭代版本V2

    网络编程 -- RPC实现原理 -- 目录 啦啦啦 V2——增加WriteQueue队列,存放selectionKey.addWriteEventToQueue()添加selectionKey并唤醒阻 ...

  10. 【代码审计】五指CMS_v4.1.0 后台存在SQL注入漏洞分析

      0x00 环境准备 五指CMS官网:https://www.wuzhicms.com/ 网站源码版本:五指CMS v4.1.0 UTF-8 开源版 程序源码下载:https://www.wuzhi ...