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 ...
随机推荐
- TF-IDF_MapReduceJava代码实现思路
TF-IDF 1. 概念 2. 原理 3. java代码实现思路 数据集: 三个MapReduce 第一个MapReduce:(利用ik分词器,将一篇博文,也就是一条记录 ...
- Tp框架查询分页显示与全部查询出来显示运行时间快慢有区别吗?
8:08:01 青春阳光 2017/4/7 8:08:01 大神在吗? Tp框架查询分页显示与全部查询出来显示运行时间快慢有区别吗? 青春阳光 2017/4/7 8:08:20 还有个问题,上传到pu ...
- vim 的各种用法,很实用哦,都是本人是在工作中学习和总结的
(一)初级个性化配置你的vim 1.vim是什么? vim是Vi IMproved,是编辑器Vi的一个加强版,一个极其强大并符合IT工程师(程序员.运维)习惯的编辑器.如果你是一名职业的SE,那么一定 ...
- 织梦中data文件夹是存放什么内容的
dede(织梦)的data文件夹下的文件及文件夹也不少,我们来一个一个的介绍下. 1. admin文件夹 admin文件夹 管理员用到的文件夹,一般是后台的配置文件. 第一个文件,idc.txt 配置 ...
- PHP 获得当前页面所有变量常量的值
get_defined_vars() - 返回由所有已定义变量所组成的数组,这个函数在二次开发的时候用起来非常给力: get_defined_constants();可以返回当前的所有常量 zend的 ...
- 图文教程:在Mac上搭建Titanium的iOS开发环境
http://mobile.51cto.com/web-317170_all.htm 跨平台开发工具Titanium的兴起之路:HTML 5是最大威胁 比较Titanium和PhoneGap两大iOS ...
- Cannot complete the install because one or more required items could not be found
弄了一天的subclipse也没装上,郁闷~~~~~~~~ 无论采用本地安装还是站点安装都不行,在安装的时候显示错误: Cannot complete the install because one ...
- git 快速入门
介绍git的基本知识.文件状态.工作区域以及一个简单的操作示例. 目录 1. git相关介绍 2. 文件状态与工作区域 3. 快速使用 1. git相关介绍 1.1 git.github.gitlab ...
- python_斐波那契数列
什么是斐波那契数列? -- 一组第从第三个值开始,每个值都等于前两个值之和的一种有意思的数列 如[1, 1, 2, 3, 5, 8, 13, 21, 34, 55] 如何用程序进行实现? -- 逻辑整 ...
- 数据库分表之Mybatis+Mysql实践(含部分关键代码)
2018年01月31日 随着我们系统用户数量的日增,业务数据处于一个爆发前,增长的数据量已经给我们的系统造成了很大的不确定.在上个周末用户量较多,并发较大的情况下,读写频繁的验证码表,数据量 ...