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 ...
随机推荐
- php中urldecode()和urlencode()起什么作用啊
urlencode()函数原理就是首先把中文字符转换为十六进制,然后在每个字符前面加一个标识符%. urldecode()函数与urlencode()函数原理相反,用于解码已编码的 URL 字符串,其 ...
- laravel中数据库在哪个文件中配置
我们使用 mysql 数据库,修改 .env: DB_HOST=localhost DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= 在mysql中创 ...
- xml报错 Parse Fatal Error :在实体引用中,实体名称必须紧跟在'&'后面
修改jndi配置文件中的密码后,重启tomcat报错如下 实际问题是xml中默认’&’是非法字符,用 & 替代
- Discuz论坛URL静态化规则urlrewrite
http://blog.csdn.net/u014181418/article/details/53467980 1.在论坛代码目录下新建文件".htaccess" vim /us ...
- git fetch, git pull 剖析
真正理解 git fetch, git pull 要讲清楚git fetch,git pull,必须要附加讲清楚git remote,git merge .远程repo, branch . commi ...
- WebSphere--安全性
WebSphere应用服务器具有很好的安全性支持.安全性简单地说就是确定谁可访问重要的系统资源,这些系统资源包括文件.目录.程序.连接和数据库.以独立模式运行WebSphere应用服务器比作为 Web ...
- Mysql的主从配置
前言:这次学习分布式的思想要配置mysql的主从复制和读写分离,我在主从配置上踩到很多坑,在此演示一遍配置过程,并附上问题的说明和自己的一些见解 Mysql主从复制的原理 附上原理图: mysql的主 ...
- android 监听返回键
android监听返回键 public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE ...
- nodejs环境设置理解
本小白今天忙了一下午,就为了设置好nodejs的环境变量. 其实理解了nodejs调用的过程就会发现环境变量的设置及其简单(当然,我是边安装边想的,不知我想的对不对) 首先,npm下载的模块分为全局模 ...
- 汉诺塔python3函数编写和过程分析
!/usr/bin/env python3 -- coding: utf-8 -- 利用递归函数计算阶乘 N! = 1 * 2 * 3 * ... * N def fact(n): if n == 1 ...