problem

728. Self Dividing Numbers

solution1: 使用string类型来表示每位上的数字;

class Solution {
public:
vector<int> selfDividingNumbers(int left, int right) {
vector<int> res;
for (int i=left; i<=right; ++i)
{
bool flag = isSDN(i);
if(flag) res.push_back(i);
}
return res;
}
bool isSDN(int num) {
string str = to_string(num);
for(auto ch : str)
{
if(ch=='' || num%(ch-'')!=) return false;
}
return true;
}
};

solution2: 使用数学计算来check每一个数字;

问题1:求解余数的语句;

问题2:需要先求解一次余数,再计算除数,即下一次计算需要用到的被除数。

class Solution {
public:
vector<int> selfDividingNumbers(int left, int right) {
vector<int> res;
for (int i=left; i<=right; ++i)
{
bool flag = isSDN(i);
if(flag) res.push_back(i);
}
return res;
}
bool isSDN(int num) {
int tmp = num;
int reminder = ;
while(tmp)
{
reminder = tmp%;//err..
tmp /= ;//err..
if(reminder == || ((num%reminder) != )) return false;
}
if(tmp==) return true;
else return false;
}
};

参考

1. Leetcode_easy_728. Self Dividing Numbers;

2. Grandyang;

【Leetcode_easy】728. Self Dividing Numbers的更多相关文章

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

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

  2. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

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

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

  4. 【HDU2138】How many prime numbers

    [题目大意] 给n个数判断有几个素数.(每个数<=2^32) 注意多组数据 [题解] 用Rabin_Miller测试跑得飞快... /************* HDU 2138 by chty ...

  5. 【Leetcode_easy】1022. Sum of Root To Leaf Binary Numbers

    problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binar ...

  6. 【Leetcode_easy】985. Sum of Even Numbers After Queries

    problem 985. Sum of Even Numbers After Queries class Solution { public: vector<int> sumEvenAft ...

  7. 【Leetcode_easy】633. Sum of Square Numbers

    problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明c ...

  8. 【Leetcode_easy】628. Maximum Product of Three Numbers

    problem 628. Maximum Product of Three Numbers 题意:三个数乘积的最大值: solution1: 如果全是负数,三个负数相乘还是负数,为了让负数最大,那么其 ...

  9. 【leetcode】Bitwise AND of Numbers Range(middle)

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

随机推荐

  1. django安装过程简介(Mac版)

    Django 中的项目和应用是什么? 简单来说,可以认为

  2. 在mysql中用int类型存储IP

    SELECT INET_ATON( '127.0.0.1' ); SELECT INET_NTOA();

  3. 25 | MySQL是怎么保证高可用的?

    在上一篇文章中,我和你介绍了binlog的基本内容,在一个主备关系中,每个备库接收主库的binlog并执行. 正常情况下,只要主库执行更新生成的所有binlog,都可以传到备库并被正确地执行,备库就能 ...

  4. [Luogu] 货车运输

    https://www.luogu.org/problemnew/show/1967 kruskal + Lca #include <iostream> #include <cstd ...

  5. python3 中的bytes类型

  6. dashucoding记录2019.6.6

    div { display:flex; flex-direction:row-reverse; } -webkit-, - ms-或-moz- CSS语法 flex-direction: row|ro ...

  7. 前端武器库之DOM练习

    1.模态对话框 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  8. 4)抽象方法不能为private,final或者static,为什么?

    抽象方法的最实质的意 义在于被未来的子类覆盖实现掉.它自己是个空方法.private的实质意义在于本类其他方法调用它.你自己是个空方法,别人调用你有什么用?所以 abstract和private在一起 ...

  9. Kettle中ETL的效率优化

    ETL效率优化 开启数据库日志记录及性能监控 如果我们想要优化一个ETL(KTR或者KJB)的性能,我们首先需要知道的就是它的瓶颈在哪里.而这些信息一般只能在ETL运行的步骤度量中看到,并且是不会持久 ...

  10. Selenium 常用JS

    滑动scroll: window.scrollTo(0,document.body.scrollHeight);