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. codeforces#572Div2 D1---Add On A Tree【思维】

    题目:http://codeforces.com/contest/1189/problem/D1 题意:给定一棵树,可以选择任意两个叶子节点对他们的路径增加一定的权值. 问对于给定的这棵树,是否可以得 ...

  2. 06_Tutorial 6: ViewSets & Routers 视图集与路由器

    1.Tutorial 6: ViewSets & Routers 视图集与路由器 0.文档 https://q1mi.github.io/Django-REST-framework-docum ...

  3. sql server 的模糊查询的用法

     查询所有姓张的同学Select * from student where left(sName,1)=‘张‘   看上去很美,如果改成查询名字中带亮的学生怎么做?换一种做法 like  Select ...

  4. CF620E New Year Tree 线段树+dfs序+bitset

    线段树维护 dfs 序是显然的. 暴力建 60 个线段树太慢,于是用 bitset 优化就好了 ~ code: #include <bits/stdc++.h> #define M 63 ...

  5. LibreOJ #115. 无源汇有上下界可行流

    二次联通门 : LibreOJ #115. 无源汇有上下界可行流 /* LibreOJ #115. 无源汇有上下界可行流 板子题 我也就会写写板子题了.. */ #include <cstdio ...

  6. RESTFUL API 安全认证方式

    一般基于REST API 安全设计常用方式有: HTTP Basic Basic admin:admin Basic YWRtaW46YWRtaW4= Authorization: Basic YWR ...

  7. visual studio code(vs code) 编译、运行、调试程序(调用g++)

    g++的安装过程忽略,记不清有没有"安装路径不能有空格"这种问题. 网上翻了几个博客,找到的配置文件在g++下都不能运行,遂折腾. 安装vscode与插件 插件为ms-vscode ...

  8. Ubuntu 14.04 indigo 安装 cartographer 1.0.0

    安装依赖(cmake 版本为2.8,我的是自带的)sudo apt-get updatesudo apt-get install -y g++ git google-mock libboost-all ...

  9. Redis删除相同前缀的key

          如何优雅地删除Redis set集合中前缀相同的key?       Redis中有删除单条数据的命令DEL,却没有批量删除特定前缀key的指令,但我们经常遇到需要根据前缀来删除的业务场景 ...

  10. (转)libvirt和qemu编译安装

    借鉴:https://www.cnblogs.com/grglym/p/8053553.html 借鉴:http://blog.chinaunix.net/uid-31410005-id-577189 ...