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. Git----拉取远程分支,git pull,git rebase,git pull --rebase的区别

    git pull 相当于自动的 fetch 和 merge 操作,会试图自动将远程库合并入本地库,在有冲突时再要求手动合并. git rebase 可以确保生产分支commit是一个线性结构,方便ro ...

  2. js插件讲解_javascript原生日历插件讲解

    效果图如下: html代码 <div class="date-control" id="date-control"> <span id=&qu ...

  3. LightOJ-1008-Fibsieve`s Fantabulous Birthday(推公式)

    链接: https://vjudge.net/problem/LightOJ-1008 题意: Fibsieve had a fantabulous (yes, it's an actual word ...

  4. 使用Java实现数据库编程-----------查询学生记录

    查询所有学生记录,包含年级名称 @Override public LIst<Student>getAllStudent() throws Exception{ List<Studen ...

  5. 十六.部署PXE网络装机

    PXE组件及过程分析 • 需要哪些服务组件? – DHCP服务,分配IP地址.定位引导程序 – TFTP服务,提供引导程序下载 – HTTP服务,提供yum安装源 • 客户机应具备的条件 – 网卡芯片 ...

  6. AS400 printer setting

    (1) CRTOUTQ OUTQ(TESTLIB/PRINTER2) (2) CRTDEVPRT ===> CRTDEVPRT DEVD(PRINTER2) DEVCLS(*LAN) TYPE( ...

  7. SQL SERVER PIVOT使用

    参照这个网址介绍 http://www.cnblogs.com/lwhkdash/archive/2012/06/26/2562979.html 一般SQL Server的函数都会识别为紫色,可是PI ...

  8. QShareMemory

    Qt提供了一种安全的共享内存的实现QSharedMemory,以便在多线程和多进程编程中安全的使用.比如说QQ的聊天的客户端,这里有个个性头象,当点击QQ音乐播放器的时候,启动QQ音乐播放器(启动一Q ...

  9. bat批处理运用

    一.简单批处理内部命令简介 1.Echo 命令 –显示 打开回显或关闭请求回显功能,或显示消息.如果没有任何参数,echo 命令将显示当前回显设置. 语法: echo [{on│off}] [mess ...

  10. leetcode解题报告(20):Rotate Array

    描述 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the arr ...