LeetCode - 728. Self Dividing Numbers
A self-dividing number is a number that is divisible by every digit it contains.
For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.
Also, a self-dividing number is not allowed to contain the digit zero.
Given a lower and upper number bound, output a list of every possible self dividing number, including the bounds if possible.
Example 1:
Input:
left = 1, right = 22
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]
Note:
- The boundaries of each input argument are
1 <= left <= right <= 10000.
class Solution {
public List<Integer> selfDividingNumbers(int left, int right) {
left = left < 1 ? 1 : left;
List<Integer> list = new ArrayList<Integer>();
if (right < left)
return list;
for (int i=left; i<=right; i++)
if (isSelf(i))
list.add(i);
return list;
}
private boolean isSelf(int n) {
String ns = String.valueOf(n);
for (int i=0; i<ns.length(); i++) {
int nsn = ns.charAt(i)-'0';
if (nsn == 0 || (n % nsn) != 0)
return false;
}
return true;
}
}
LeetCode - 728. Self Dividing Numbers的更多相关文章
- LeetCode 728 Self Dividing Numbers 解题报告
题目要求 A self-dividing number is a number that is divisible by every digit it contains. For example, 1 ...
- 【Leetcode_easy】728. Self Dividing Numbers
problem 728. Self Dividing Numbers solution1: 使用string类型来表示每位上的数字: class Solution { public: vector&l ...
- 【LeetCode】728. Self Dividing Numbers 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 循环 filter函数 数字迭代 日期 题目地址:h ...
- [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 ...
- Python 解leetcode:728. Self Dividing Numbers
思路:循环最小值到最大值,对于每一个值,判断每一位是否能被该值整除即可,思路比较简单. class Solution(object): def selfDividingNumbers(self, le ...
- [LeetCode] 728. Self Dividing Numbers_Easy tag: Math
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, ...
- 728. Self Dividing Numbers
class Solution { public: vector<int> selfDividingNumbers(int left, int right) { vector<int& ...
- LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters
LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters 题记 刷LeetCod ...
随机推荐
- 关于Set对象(ES6)
今天初次接触ES6,发现确实挺神奇的,许多用以前方法去实现需要一大串代码的,用ES6竟然几句就搞定了. 这里我要说的是Set对象.Set对象是ES6中新增的类型,可以自动排除重复项,生成Set对象后, ...
- 用adb录制手机屏幕视频
adb shell screenrecord命令可以用来录制Android手机视频 screenrecord是一个shell命令,支持Android4.4(API level 19)以上,支持视频格式 ...
- webkit
HTML, 从HTML文档的开始到结束排列: <meta name="viewport" content="width=device-width, initial- ...
- Java XML 序列化和反序列化
Utils 类: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWr ...
- 【笔记】npm 安装 vue-cli
最近完成了慕课网的 高仿饿了么webApp 课程,对于vue 的认识有了更深一步的认识,但是其脚手架 vue-cli 的安装流程还是有点懵,于是今天重新试了一遍加深认识 网上参考过一些有用的教程在这里 ...
- c oth
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- linux_Nginx优化
1. 更改默认用户 a. 在nginx.conf中添加user指定用户 user web_nginx web_nginx; # nginx 用户大家都知道,通过更改默认用户实现,和http同级 b. ...
- 计算机改名引发的ORA
近期上班时,由于开机时老是提示" 局域网出现计算机重名冲突",于是把计算机名字给改了,从PC2010081312zeo改为了CXBIKKKKKKK,结果第二天来的时候,用PL/SQ ...
- js 生成 UUID
在项目中遇到要生成 UUID 的需求,第一反应就是有没有原生的生成方法,找了找,发现没有,只能自己建立算法 function. 下面是我用的算法 function uuid(len, radix) { ...
- mysql数据库安装注意事项:
mysql数据库安装注意事项: https://jingyan.baidu.com/article/642c9d34aa809a644a46f717.html(安装教程) 注意语言设置为gbk可以解决 ...