【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 ...
随机推荐
- Learning Spark (Python版) 学习笔记(一)----RDD 基本概念与命令
<Learning Spark>这本书算是Spark入门的必读书了,中文版是<Spark快速大数据分析>,不过豆瓣书评很有意思的是,英文原版评分7.4,评论都说入门而已深入不足 ...
- Nginx 负载均衡条件下 Tomcat 共享Session (Java)(一)
1.修改tomcat 下 conf/context.xml 在</Context>里面加入以下代码 <Valve className="com.orangefunctio ...
- 使用Python+selenium实现第一个自动化测试脚本
原blog 一,安装Python. python官方下载地址:https://www.python.org/downloads/ 安装后点击开始菜单,在菜单最上面能找到IDLE. IDLE是pytho ...
- TensorFlow(八):tensorboard可视化
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data from tensorflow.c ...
- Web前端-JavaScript基础教程下
Web前端-JavaScript基础教程下 <script>有6个属性: async对外部脚本有效,可以用来异步操作,下载东西,不妨碍其他操作. charset为src属性指定字符集. d ...
- chrome的内存限制
推荐阅读:https://www.cnblogs.com/chengxs/p/10919311.html chrome内存限制 存在限制 Chrome限制了所能使用的内存极限(64位为1.4GB,32 ...
- Shiro + Redis集成思路
首先,确保Spring配置完毕了. 集成Shiro 1.在pom.xml中追加依赖 <dependency> <groupId>org.apache.shiro</gro ...
- Java基础系列 - 抽象类,子类继承
package com.company; /** * 抽象类继承 * 用abstract修饰类就是抽象类 * 用abstract修饰方法就是抽象方法(一般使用比较少) * 抽象类不能被实例化 */ p ...
- ICEM-带肋圆柱
原视频下载地址:https://yunpan.cn/cqUj6H9un37F2 访问密码 91af
- GO windows下编译luajit
1 GO嵌入luajit需要用到cgo,使用cgo需要安装gcc,在windows上下载MinGW-W64安装上配置好环境变量就可以 2 gcc编译luajit,生成.a文件. 把LuaJIT-2.0 ...