【Leetcode_easy】728. Self Dividing Numbers
problem
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的更多相关文章
- 【LeetCode】728. Self Dividing Numbers 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 循环 filter函数 数字迭代 日期 题目地址:h ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- 【LeetCode】165. Compare Version Numbers 解题报告(Python)
[LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- 【HDU2138】How many prime numbers
[题目大意] 给n个数判断有几个素数.(每个数<=2^32) 注意多组数据 [题解] 用Rabin_Miller测试跑得飞快... /************* HDU 2138 by chty ...
- 【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 ...
- 【Leetcode_easy】985. Sum of Even Numbers After Queries
problem 985. Sum of Even Numbers After Queries class Solution { public: vector<int> sumEvenAft ...
- 【Leetcode_easy】633. Sum of Square Numbers
problem 633. Sum of Square Numbers 题意: solution1: 可以从c的平方根,注意即使c不是平方数,也会返回一个整型数.然后我们判断如果 i*i 等于c,说明c ...
- 【Leetcode_easy】628. Maximum Product of Three Numbers
problem 628. Maximum Product of Three Numbers 题意:三个数乘积的最大值: solution1: 如果全是负数,三个负数相乘还是负数,为了让负数最大,那么其 ...
- 【leetcode】Bitwise AND of Numbers Range(middle)
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
随机推荐
- BZOJ1257: [CQOI2007]余数之和——整除分块
题意 求 $\sum _{i=1}^n k \ mod \ i$($1\leq n,k\leq 10^9$). 分析 数据范围这么大 $O(n)$ 的复杂度也挺不住啊 根据取模的意义,$k \ mod ...
- Spring Boot学习--spring-boot-starter-parent及starters(转)
在官方文档的第三部分的13块讲述了引用的管理,官方推荐的是使用Maven和Gradle. 我一直在用的是maven,而且使用maven有些优势–spring-boot-starter-parent,这 ...
- sql server update....set.... from ....where....
工作中遇到的 update 的更新方法 以前update 表 set 列 = 新值 稍稍进阶 update 表 set 列 = (select 值 from 表 where ...) ...
- springboot使用rabbitmq-Topic模式,亲自实测能用!!!
0.项目目录截图 ===================================================================== springboot的版本: <gr ...
- luogu 3248
直接向原树加子树是不可能的考虑重新建立这样一颗树,我们称之为 S 树 将每次需要添加的子树看做一个点,称之为 S 点 新建的树就是由这些点构成的,那么树的大小是合理的 初始节点为整棵原树由于添加的子树 ...
- linux系列(九):touch命令
1.命令格式: touch [选项] 文件 2.命令功能: touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间. 3.命令参数: -a 或--time=atime或--time=a ...
- codeforces626F
CF626F Group Projects 有n个学生,每个学生有一个能力值ai.现在要把这些学生分成一些(任意数量的)组,每一组的“不和谐度”是该组能力值最大的学生与能力值最小的学生的能力值的差. ...
- Python基础之各种推导式玩法
一.推导式套路 除了我们之前所学习的列表推导式和生成器表达式之外,还有字典推导式.集合推导式等等. 下面就是一个以列表推导式为例的推导式详细格式,同样适用于其他推导式. variable = [out ...
- Dp优化之决策单调栈优化
证明:g(i) ≤ g(j) (i ≤ j) 令 d=g(i) , k<d , 设cut = x表示 f(i) = f(x) + w[x,i] ( x < i ) 构造一个式子: ...
- 关于$internalField边界条件【翻译】
翻译自:CFD-online 帖子地址:http://www.cfd-online.com/Forums/openfoam-pre-processing/122386-about-internalfi ...