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 ...
随机推荐
- <form>(表单)标签和常用的类型
1.定义和用法 <form> 标签用于为用户输入创建 HTML 表单. 表单能够包含 input 元素,比如文本字段.复选框.单选框.提交按钮等等. 表单还可以包含 menus.texta ...
- iOS多线程方案总结及使用详解
本篇文章整理了几种iOS中主要的多线程方案,提供了Swift和Objective-C两种语言的写法. 概述 iOS目前有四种多线程解决方案: NSThread GCD NSOperation Pthr ...
- Python学习之for循环--输出1-100中的偶数和登录身份认证
输出1-100中的偶数 效果图: 实现代码: for i in range(2,101,2): print(i,end = '\t') if(i == 34): print('\n') if (i = ...
- It\'s A Good Day To Die
[00:01.82]Courage! Duty! Honor! [00:05.67]We call upon our troopers [00:07.90]In this our darkest ho ...
- python-web-下载所有xkcd漫画
下载所有xkcd漫画 # downloads every single xkcd comic import requests,os,bs4 url='http://xkcd.com' # start ...
- javascript基础:事件
事件: 概念:某些组件被执行了某些操作后,触发某些代码的执行 * 事件:某些操作,如:单击,双击,键盘按下了,鼠标移动了 * 事件源:组件.如:按钮 文本输入框.... * 监听器:代码 * ...
- Linux 定时任务执行 php artisan
*/ * * * * php /www/wwwroot/project/artisan command:exec postNews 5分钟执行一次
- [Array]485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
- TZ_05_Spring_事物的xml开发和annotation开发
1.Spring_事物的xml开发 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=& ...
- laravel-admin列表排序在使用了$grid->model()->latest()后$grid其它加上sortable()可排序的列在排序时不起作用
laravel-admin这个基于laravel的后台框架,简单易用,$grid的默认排序是主键升序的排列方式,但在使用了`$grid->model()->latest();`自定义默认排 ...