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 == 0128 % 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的更多相关文章

  1. LeetCode 728 Self Dividing Numbers 解题报告

    题目要求 A self-dividing number is a number that is divisible by every digit it contains. For example, 1 ...

  2. 【Leetcode_easy】728. Self Dividing Numbers

    problem 728. Self Dividing Numbers solution1: 使用string类型来表示每位上的数字: class Solution { public: vector&l ...

  3. 【LeetCode】728. Self Dividing Numbers 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 循环 filter函数 数字迭代 日期 题目地址:h ...

  4. [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 ...

  5. Python 解leetcode:728. Self Dividing Numbers

    思路:循环最小值到最大值,对于每一个值,判断每一位是否能被该值整除即可,思路比较简单. class Solution(object): def selfDividingNumbers(self, le ...

  6. [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 ...

  7. 728. Self Dividing Numbers可以自己除以自己的数字

    [抄题]: A self-dividing number is a number that is divisible by every digit it contains. For example, ...

  8. 728. Self Dividing Numbers

    class Solution { public: vector<int> selfDividingNumbers(int left, int right) { vector<int& ...

  9. LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters

    LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters 题记 刷LeetCod ...

随机推荐

  1. Spark算子--mapValues

    转载请标明出处http://www.cnblogs.com/haozhengfei/p/ccc9d6b5c46ac7209c1e104bd219bfb4.html mapValues--Transfo ...

  2. Arrays类详解

    数组是数据结构中最简单的一种类型.在平常的使用上也比较多见.今天就来总结一下数组在使用过程中的一些心得 1.java中包装数组的一些基本用法的抽象类  java.util.Arrays.这个类中包含操 ...

  3. Hadoop问题:Incorrect configuration: namenode address dfs.namenode.rpc-address is not configured

    问题描述:Incorrect configuration: namenode address dfs.namenode.rpc-address is not configured 问题分析:core- ...

  4. struts配置json需要的jar包

  5. eclipse导入web项目变成java项目解决办法

    右键工程,properties-> Project Facets-> 点convert to faceted..连接 -> 把Dynamic Web Moudle勾上

  6. requireJs 踩的坑

    <!-- RequireJS --> <script src="assets/js/require.min.js" data-main="assets/ ...

  7. html动态生成的代码,绑定事件

    如果使用jQuery,你可以这样写: // .class为你绑定事件的动态生成的结点 $(document).on('click', '.class', function() { // 你要绑定的事件 ...

  8. 2.CLI标准

    CLI  简称(CLI标准) 通用语言架构    维基百科地址: http://zh.wikipedia.org/wiki/通用语言架构 是一个开放的  技术规范  .它是由  微软  联合  惠普  ...

  9. junit3对比junit4

    本文内容摘自junit实战,感谢作者的无私奉献. 个人觉得每个开源包的版本对比意义不大,闲来无事,这里就来整理一下好了.本文名为junit3对比junit4,但是我通过这篇博客主要也是想统一的来整理下 ...

  10. VMware PowerCLi 使用示例

    这几天研究PowerCLI,积累了几个例子,记下来,以便以后或者大家使用.部分例子来着网络,具体出处参考附录 1 获取vm 磁盘 和磁盘对应的datastore的信息 这个例子可以针对一台虚机有多个磁 ...