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. P2P结构与Quorum机制------《Designing Data-Intensive Applications》读书笔记8

    前文涉及到了很多与Leader相关的算法,大家有木有想过,王侯将相,宁有种乎,既然Leader这么麻烦,干脆还是采用P2P模型吧,来个大家平等的架构.本篇需要和大家探讨的就是多副本下实现民主政治的Qu ...

  2. Java数据持久层框架 MyBatis之背景知识三

    摘录自:http://www.cnblogs.com/lcngu/p/5437281.html 对于MyBatis的学习而言,最好去MyBatis的官方文档:http://www.mybatis.or ...

  3. Java的栈和队列

    package com.ipmotor.sm.db;import java.util.LinkedList;import java.util.Queue;import java.util.Stack; ...

  4. php 利用Gd库添加文字水印乱码的问题及解决方案

    最近一个项目进行了服务器迁移,部署后发现 ,其中一个为图片添加水印文字的功能出现了乱码问题,确认功能代码不存在问题,同时项目代码都是使用UTF-8编码,不存在编码问题,也检查排除了字体文件出现问题的可 ...

  5. java面向对象的三大特性——继承

    ul,ol { margin: 0; list-style: none; padding: 0 } a { text-decoration: none; color: inherit } * { ma ...

  6. 1.JavaScript 教程:基础语法

    简介: JavaScript web 开发人员必须学习的 3 门语言中的一门: HTML 定义了网页的内容 CSS 描述了网页的布局 JavaScript 网页的行为 用法: (1)HTML 中的脚本 ...

  7. python2.7.5 安装pip

    1 先安装setuptools 下载地址:https://pypi.python.org/pypi/setuptools#downloads 将下载后的tar文件解压,用CMD模式进入到解压后的文件所 ...

  8. java8大基本数据类型

    基本类型 字节数 位数 最大值 最小值 byte 1byte 8bit 2^7 - 1 -2^7 short 2byte 16bit 2^15 - 1 -2^15 int 4byte 32bit 2^ ...

  9. jdbc参数

    JDBC连接池参数:    jdbc.initialSize=0       //初始化连接    jdbc.maxActive=30     //连接池的最大数据库连接数,设为0表示无限制    j ...

  10. 【转】centos安装vim7.4

    centos安装vim7.4   系统版本centos6.4; root权限 su - root     卸载 $ rpm -qa | grep vim $ yum remove vim vim-en ...