自除数 是指可以被它包含的每一位数除尽的数。

例如,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]

注意:

  • 每个输入参数的边界满足 1 <= left <= right <= 10000。
class Solution {
public:
vector<int> selfDividingNumbers(int left, int right)
{
vector<int> res;
for(int i = left; i <= right; i++)
{
if(i < 10)
{
res.push_back(i);
}
else
{
vector<int> ary;
if(GetDigit(i, ary))
{
int len = ary.size();
int flag = true;
for(int j = 0; j < len; j++)
{
if(i % ary[j] != 0)
{
flag = false;
break;
}
}
if(flag)
res.push_back(i);
}
}
}
return res;
} bool GetDigit(int x, vector<int> &ary)
{
while(x)
{
int temp = x % 10;
if(temp == 0)
return false;
ary.push_back(temp);
x /= 10;
}
return true;
}
};

Leetcode728.Self Dividing Numbers自除数的更多相关文章

  1. 【Leetcode_easy】728. Self Dividing Numbers

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

  2. [Swift]LeetCode728. 自除数 | Self Dividing Numbers

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

  3. C#LeetCode刷题之#728-自除数(Self Dividing Numbers)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3889 访问. 自除数 是指可以被它包含的每一位数除尽的数. 例如 ...

  4. [LeetCode] Self Dividing Numbers 自整除数字

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

  5. LeetCode - 728. Self Dividing Numbers

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

  6. LeetCode 728 Self Dividing Numbers 解题报告

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

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

  8. 728. Self Dividing Numbers可以自己除以自己的数字

    [抄题]: A self-dividing number is a number that is divisible by every digit it contains. For example, ...

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

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

随机推荐

  1. 移动端网站如何开发(电脑端网站到手机端网站我们需要在html代码中添加哪个meta标签)

    移动端网站如何开发(电脑端网站到手机端网站我们需要在html代码中添加哪个meta标签) 一.总结 一句话总结: 添加viewport标签:meta name="viewport" ...

  2. 官方 NSIS 插件全集简单介绍

    Math plugin (contain examples) -- 数学函数插件,NSIS 软件已包含,这个不用说了吧,计算的时候必用. System plugin (contain examples ...

  3. 洛谷p1605--迷宫 经典dfs

    https://www.luogu.org/problemnew/show/P1605 用这种题来复习一下dfs 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和终点坐标,问 ...

  4. mysql不创建表 <property name="hbm2ddl.auto">update</property> 无效

    netbeans win10 mysql8 hibernate 4.3.11 dakai mysql的general_log发现并没有创建表的语句 未完待续 今天又遇到不创建表的问题 但是问题比较奇怪 ...

  5. boxFilter in opencv

    , -),bool normalize=true,int borderType=BORDER_DEFAULT) Smoothes image using box filter Parameters: ...

  6. 2019-8-31-dotnet-获取用户设备安装了哪些-.NET-Framework-框架

    title author date CreateTime categories dotnet 获取用户设备安装了哪些 .NET Framework 框架 lindexi 2019-08-31 16:5 ...

  7. leetcode 57 Insert Interval & leetcode 1046 Last Stone Weight & leetcode 1047 Remove All Adjacent Duplicates in String & leetcode 56 Merge Interval

    lc57 Insert Interval 仔细分析题目,发现我们只需要处理那些与插入interval重叠的interval即可,换句话说,那些end早于插入start以及start晚于插入end的in ...

  8. Rabbitmq交换机三种模式介绍

    1.topic 将路由键和某模式进行匹配.此时队列需要绑定要一个模式上.符号“#”匹配一个或多个词,符号“*”匹配不多不少一个词.因此“abc.#”能够匹配到“abc.def.ghi”,但是“abc. ...

  9. promise基础和进阶

    本文不对Promise的做过深的解析,只对基础的使用方法,然后会记录一些promise的使用技巧,可以巧妙的解决异步的常见问题. 在过去一直理解的是解决了一直异步回调的坑,但是用了npm async之 ...

  10. PHP获取搜索引擎关键词

    有时候我们需要知道用户通过哪个搜索引擎,通过拿个关键词访问我们页面,当然js也可以实现,这里介绍下php的实现代码,包含(百度.谷歌.雅虎.搜狗.搜搜.必应.有道)几大搜索引擎的获取方法. //获取来 ...