【LeetCode】728. Self Dividing Numbers

学习提速专享!AI工具全家桶免费用 限时购周边加赠Coding Plan Lite,解锁20+主流AI工具,写代码、查资料快人一步! 阅读详情

728Self Dividing Numbers

https://leetcode.com/problems/self-dividing-numbers/description/


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.


分析:

就是判断一个数字是否是自除数,如果这个数字能整除它每一位数上的数字那么就是自除数


sol1: 

将这个数字转换成str形式

class Solution:
    def selfDividingNumbers(self, left, right):
        return [i for i in range(left,right+1) if not any([m == '0' or i % int(m) != 0 for m in str(i)])]



除数 除数——2020.12.14题目思路解法 题目 自除数 是指可以被它包含的每一位数除尽的数。 例如,128 是一个自除数,因为 128 % 1 == 0,128 % 2 == 0,128 % 8 == 0。 还有,自除数不允许包含 0 。 给定上边界和下边界数字,输出一个列表,列表的元素是边界(含边界)内所有的自除数。 示例 1: 输入: 上边界left = 1, 下边界right = 22 输出: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22] 思路解法 第一想到 阅读详情

相关推荐

728.除数

728.除数 难度:简单 时间:2022年3月31日 自除数 是指可以被它包含的每一位数整除的数。 例如,128 是一个 自除数 ,因为 128 % 1 == 0,128 % 2 == 0,128 % 8 == 0。 自除数 不允许包含 0 。 给定两个整数 left 和 right ,返回一个列表,列表的元素是范围 [left, right] 内所有的 自除数 。 示例 1: 输入:left = 1, right = 22 输出:[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1.

m0_59690208的博客 566

【自除数】和【除自身以外数组的乘积(两次优化)】

最近的OJ练习用到动态分配内存malloc函数更频繁了,现在已经能够基础地运用它解决算法问题了,不得不说,不能使用变长数组确实麻烦多了…

StuLearn-LJC的博客 221

除数的判断——C语言实现

除数的判断——C语言实现

qq_63918780的博客 1673

LeetCode】自除数

除数 是指可以被它包含的每一位数除尽的数。 例如,128 是一个自除数,因为 128 % 1 == 0,128 % 2 == 0,128 % 8 == 0。 还有,自除数不允许包含 0 。 给定上边界和下边界数字,输出一个列表,列表的元素是边界(含边界)内所有的自除数。 示例 1: 输入: 上边界left = 1, 下边界right = 22 输出: [1, 2, 3, 4, 5,...

QiuBika_061的博客 1338

leetcode-728. Self Dividing Numbers

728. Self Dividing Numbersself-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, a

link98 1777

[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, 128 is a self-dividing number because 128 % 1 == 0,

user_name_is_so_long的博客 538

LeetCode728 Self Dividing Numbers

题目: 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 == 0, 128 % 2 == 0, and 128 % 8 == 0. ...

zhangjun62的博客 175

Leetcode 728 Self Dividing Numbers

class Solution { public List<Integer> selfDividingNumbers(int left, int right) { List<Integer> ans=new ArrayList<Integer>(); for(int i=left;i<=right;++i){ ...

Polanwind 157

LeetCode //C - 728. Self Dividing Numbers

Self-dividing numbers are numbers divisible by every digit they contain, excluding those with the digit zero. Given a range [left, right], the task is to identify all such numbers within this range. The solution involves iterating through each number in th

Made in Code 1201

LeetCode 728. Self Dividing Numbers

LeetCode 728. Self Dividing NumbersDescriptionA 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 == 0, 128 % 2 ==

Vimer.Bai的博客 273

leetcode728. Self Dividing Numbers

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 == 0, 128 % 2 == 0, and 128 % 8 == 0. Also, a self-dividin...

ghscarecrow的博客 363

[LeetCode]728. Self Dividing Numbers

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 == 0, 128 % 2 == 0, and 128 % 8 == 0. Also, a self-dividi...

a342500329a的专栏 228

Leetcode728. Self Dividing Numbers

题目地址: https://leetcode.com/problems/self-dividing-numbers/ 给定一个正整数区间范围[l,r][l, r][l,r],挑出所有能被其各个位上的数整除的数字(不允许其中某一位为000)。直接逐个判断即可。代码如下: import java.util.ArrayList; import java.util.List; public class Solution { public List<Integer> selfDividingNu

数学、算法爱好者的博客 161

leetCode刷题记录之728Self Dividing Numbers

leetCode刷题记录之728 原题 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 == 0, 128 % 2 == 0, and 128 % 8 == 0. Al...

gunsmoke的专栏 169

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, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0,...

ccystewart的博客 201

[leetcode]728. Self Dividing Numbers

[leetcode]728. Self Dividing Numbers Analysis ummmm~—— [ummmm~] A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number b...

weixin_32135877的博客 169
上一篇: 【4】如何理解CNN中的卷积?
下一篇: 扇形涂色问题(Python)
cheney康
博客等级 码龄14年 166粉丝 122原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值