Leetcode728.Self Dividing Numbers自除数
自除数 是指可以被它包含的每一位数除尽的数。
例如,128 是一个自除数,因为 128 % 1 == 0,128 % 2 == 0,128 % 8 == 0。
还有,自除数不允许包含 0 。
给定上边界和下边界数字,输出一个列表,列表的元素是边界(含边界)内所有的自除数。
示例 1:
输入: 上边界left = 1, 下边界right = 22 输出: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
注意:
- 每个输入参数的边界满足 1 <= left <= right <= 10000。
class Solution {
public:
vector<int> selfDividingNumbers(int left, int right)
{
vector<int> res;
for(int i = left; i <= right; i++)
{
if(i < 10)
{
res.push_back(i);
}
else
{
vector<int> ary;
if(GetDigit(i, ary))
{
int len = ary.size();
int flag = true;
for(int j = 0; j < len; j++)
{
if(i % ary[j] != 0)
{
flag = false;
break;
}
}
if(flag)
res.push_back(i);
}
}
}
return res;
}
bool GetDigit(int x, vector<int> &ary)
{
while(x)
{
int temp = x % 10;
if(temp == 0)
return false;
ary.push_back(temp);
x /= 10;
}
return true;
}
};
Leetcode728.Self Dividing Numbers自除数的更多相关文章
- 【Leetcode_easy】728. Self Dividing Numbers
problem 728. Self Dividing Numbers solution1: 使用string类型来表示每位上的数字: class Solution { public: vector&l ...
- [Swift]LeetCode728. 自除数 | Self Dividing Numbers
A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...
- C#LeetCode刷题之#728-自除数(Self Dividing Numbers)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3889 访问. 自除数 是指可以被它包含的每一位数除尽的数. 例如 ...
- [LeetCode] Self Dividing Numbers 自整除数字
A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...
- LeetCode - 728. Self Dividing Numbers
A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...
- LeetCode 728 Self Dividing Numbers 解题报告
题目要求 A self-dividing number is a number that is divisible by every digit it contains. For example, 1 ...
- [LeetCode&Python] Problem 728. Self Dividing Numbers
A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...
- 728. Self Dividing Numbers可以自己除以自己的数字
[抄题]: A self-dividing number is a number that is divisible by every digit it contains. For example, ...
- 【LeetCode】728. Self Dividing Numbers 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 循环 filter函数 数字迭代 日期 题目地址:h ...
随机推荐
- PAT甲级——A1046 Shortest Distance
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...
- js前台中获取后台传的值
后台controller String ifOffice = "yes";req.setAttribute("ifOffice", ifOffice); 前台j ...
- mysql api 不支持source命令
今天写了个代码 <?php ..... mysql_query("source /tmp/cr.sql",$link); ..... ?> 结果死活cr.sql的SQL ...
- npm 安装删除模块
npm安装模块 [npm install xxx]利用 npm 安装xxx模块到当前命令行所在目录: [npm install -g xxx]利用npm安装全局模块xxx: 本地安装时将模块写入pac ...
- c++使用优先队列时自定义优先出队顺序(和sort)
优先队列也是一种先进先出的数据结构,元素从队尾入队,从队头出队,但是优先队列相较一般队列多了一个判断优先级的功能,在当前队列中,优先级最高的元素将被第一个删除. 先看一下优先队列的定义 templat ...
- TZ_08_maven把第三方 jar 包放入本地仓库或私服
--安装第三方jar包到本地仓库 需求:首先下载jar包并且找到对应的 -DgroupId=? -DartifactId=? -Dversion=? -Dpackaging=jar -Dfile=j ...
- 利用jquery模拟select效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 整理Mysql无法创建外键的原因
在MySQL中创建外键时,经常会遇到问题而失败,这是因为mysql中还有很多细节需要我们去留意,我自己总结并查阅资料后列出了以下几种常见原因. 1. 两个字段的类型或者大小不严格匹配.例如,如果一个 ...
- Redis之高可用、集群、云平台搭建
原文:Redis之高可用.集群.云平台搭建 文章大纲 一.基础知识学习二.Redis常见的几种架构及优缺点总结三.Redis之Redis Sentinel(哨兵)实战四.Redis之Redis Clu ...
- <a>标签操作
1.点击后onclick事件失效,变灰,不可用 onclick(this); //事件传递this对象 function viewMm(obj) { $(obj).removeAttr("o ...