【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 ...
随机推荐
- xcode 查看stastic
点GPU 双击柱状图 从上面list里点performance
- TDOA Delayed Tx 实现以及验证
在博文:https://www.cnblogs.com/tuzhuke/p/11638221.html 中描述了delayed tx实现方法,这里贴出全部delayed tx 代码以及对应验证代码 1 ...
- java上传超大文件
上周遇到这样一个问题,客户上传高清视频(1G以上)的时候上传失败. 一开始以为是session过期或者文件大小受系统限制,导致的错误.查看了系统的配置文件没有看到文件大小限制,web.xml中sees ...
- P3066 [USACO12DEC] 逃跑的Barn 左偏树
P3066 逃跑的Barn 左偏树 题面 题意:给出以1号点为根的一棵有根树,问每个点的子树中与它距离小于等于l的点有多少个. 注意到答案的两个性质: 一个点的所有答案一定包含在其所有儿子的答案中 如 ...
- TensorFlow(一):准备
我的环境:win10+python3.6.4(64位) 一:安装python 根据自己的电脑下载python(32位或者64位)-->安装教程 安装好python后记得配置pip源,使用官方的源 ...
- surprise库官方文档分析(二):使用预测算法
1.使用预测算法 Surprise提供了一堆内置算法.所有算法都派生自AlgoBase基类,其中实现了一些关键方法(例如predict,fit和test).可以在prediction_algorith ...
- (6)打鸡儿教你Vue.js
循环语句 循环使用 v-for 指令 <div id="app"> <ol> // 有序 <li v-for="item in items& ...
- 小程序开发--API之登录授权逻辑
小程序登录授权获取逻辑 原生的小程序提供许多开放接口供使用者开发,快速建立小程序内的用户体系. 下面将小程序校验.登录.授权.获取用户信息诸多接口串联起来,以便更直观的认识到这些接口是如何在实际应用中 ...
- Js 之cookie插件(jquery.cookie.js)
一.代码 (function (factory) { if (typeof define === 'function' && define.amd) { // AMD define([ ...
- OpenFOAM的PISO算法【转载】
转载自:http://openfoam.blog.sohu.com/94234375.html 流体力学的控制方程是耦合方程组,形式上体现为连续方程和运动方程的耦合,变量上体现为速度和压强的耦合.在数 ...