Python 解leetcode:728. Self Dividing Numbers
思路:循环最小值到最大值,对于每一个值,判断每一位是否能被该值整除即可,思路比较简单。
class Solution(object):
def selfDividingNumbers(self, left, right):
"""
:type left: int
:type right: int
:rtype: List[int]
"""
ret = []
for i in range(left, right+1):
val = i
flag = 1
while i:
remain = i % 10
if not remain or val % remain != 0:
flag = 0
break
i /= 10
if flag:
ret.append(val)
return ret
Python 解leetcode:728. Self Dividing Numbers的更多相关文章
- 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_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 ...
- [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 ...
- Python 解leetcode:2. Add Two Numbers
题目描述:输入两个非空单链表,链表的每个结点的值是一个1位数整数,两个链表都是一个大整数每一位的逆序排序,求这两个链表代表的整数的和的链表值: 思路: 分别遍历两个链表,转化成相应的整数,求和后把结果 ...
- Python 解LeetCode:Intersection of Two Arrays
最近,在用解决LeetCode问题的时候,做了349: Intersection of Two Arrays这个问题,就是求两个列表的交集.我这种弱鸡,第一种想法是把问题解决,而不是分析复杂度,于是写 ...
- Python 解leetcode:48. Rotate Image
题目描述:把一个二维数组顺时针旋转90度: 思路: 对于数组每一圈进行旋转,使用m控制圈数: 每一圈的四个元素顺时针替换,可以直接使用Python的解包,使用k控制每一圈的具体元素: class So ...
- Python 解LeetCode:671. Second Minimum Node In a Binary Tree
题目在这里,要求一个二叉树的倒数第二个小的值.二叉树的特点是父节点的值会小于子节点的值,父节点要么没有子节点,要不左右孩子节点都有. 分析一下,根据定义,跟节点的值肯定是二叉树中最小的值,剩下的只需要 ...
随机推荐
- bzoj 5072
对于某一大小的连通子图包含的黑点的数目的最大值和最小值都能取到考虑树形dp$f[i][j]$ 表示从 $i$ 的子树中选出大小为 $j$ 的联通子图黑点数目的最小值$g[i][j]$ 表示从 $i$ ...
- busTrace VS HW protocol analyzer - 好东西推荐
最近在找PCIe/NVMe协议分析仪,发现一款软件分析仪:busTRACE,非常不错的工具,对于从事协议开发的同胞们,是个福利,下面把硬件和软件两种分析仪的各自的优势比较了一下(来自busTrace文 ...
- 利用chrome devtool 观察页面占用内存
推荐阅读:解决内存问题 1. 任务管理器 我们看看下面这幅图: 内存占用空间:原生内存,Dom节点就是存在原生内存里面的. Javascript使用的内存:代表JS堆内存,我们只需要关心括号里面的值( ...
- 指针——可能我学的还只是c++的皮毛
C. 线性链表的插入与删除 单点时限: 2.0 sec 内存限制: 256 MB 实现线性链表的插入与删除操作 只需完成给定函数的定义. NODE* insertLinklist(NODE* head ...
- W: GPG error: http://ppa.launchpad.net trusty InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 8CF63AD3F06FC659
报错信息: W: GPG error: http://ppa.launchpad.net trusty InRelease: The following signatures couldn't be ...
- 应用fluent二维单向流泥沙冲刷作用下河床变形代码【转载】
本代码转载自:http://www.codeforge.cn/read/260028/keti_2d_b.c__html #include "udf.h" #define Rho ...
- ETL定义、四大模块及子系统说明
ETL定义.四大模块及子系统说明 ——<Pentaho Kettle解决方案>读书笔记 罗小川 目前公司正在进行数据仓库的建设的前期需求整理和项目启动阶段,想简单来谈一下自己对目前公司在用 ...
- @Configuration,@ConfigurationProperties,@EnableConfigurationProperties
@Configuration API: https://www.javadoc.io/doc/org.springframework/spring-context/5.0.7.RELEASE @Con ...
- vgg16 感受野计算
code: vgg_16 = [ [3, 1], [3, 1], [2, 2], [3, 1], [3, 1], [2, 2], [3, 1], [3, 1], [3, 1], [2, 2], [3, ...
- Python 自学笔记(四)
1.for...in...循环语句 1-1.遍历列表 1-2.遍历字典 1-2-1.遍历字典的键和值 1-2-2.遍历字典的键值(一) 1-2-3.遍历字典的键值(二) 1-2-4.遍历字典的值 1- ...