728. 自除数

自除数 是指可以被它包含的每一位数除尽的数。

例如,128 是一个自除数,因为 128 % 1 == 0,128 % 2 == 0,128 % 8 == 0。

还有,自除数不允许包含 0 。

给定上边界和下边界数字,输出一个列表,列表的元素是边界(含边界)内所有的自除数。

示例 1:

输入:

上边界left = 1, 下边界right = 22

输出: [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 15, 22]

注意:

每个输入参数的边界满足 1 <= left <= right <= 10000。

class Solution {
public List<Integer> selfDividingNumbers(int left, int right) {
List<Integer> list = new ArrayList<>();
for(int i = left;i <= right;i++){
if(dividnum(i)){
list.add(i);
}
}
return list;
} private boolean dividnum(int num){
int n = num;
while(num != 0){
if(num % 10 == 0 || n % (num%10) != 0){
return false;
}
num /= 10;
}
return true;
}
}

Java实现 LeetCode 728 自除数(暴力)的更多相关文章

  1. LeetCode 728. 自除数

    题目链接:https://leetcode-cn.com/problems/self-dividing-numbers/ 给定上边界和下边界数字,输出一个列表,列表的元素是边界(含边界)内所有的自除数 ...

  2. C# 刷遍 Leetcode 面试题系列连载(3): No.728 - 自除数

    前文传送门: C#刷遍Leetcode面试题系列连载(1) - 入门与工具简介 C#刷遍Leetcode面试题系列连载(2): No.38 - 报数 系列教程索引 传送门:https://enjoy2 ...

  3. Java for LeetCode 060 Permutation Sequence

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  4. Java for LeetCode 044 Wildcard Matching

    Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...

  5. Java for LeetCode 216 Combination Sum III

    Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...

  6. Java for LeetCode 214 Shortest Palindrome

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  7. Java for LeetCode 212 Word Search II

    Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...

  8. Java for LeetCode 211 Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...

  9. Java for LeetCode 210 Course Schedule II

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

随机推荐

  1. 【Kafka】CAP理论以及CAP定律

    目录 CAP理论 概述 Consistency Availability Partition Tolerance CAP理论 概述 1988年,加州大学计算机科学家Eric Brewer 提出了分布式 ...

  2. xml(4)

    schema约束 dtd语法:<!ELEMENT 元素名称 约束> schema符合xml的语法,xml语句 一个xml中可以有多个schema,多个schema用名称空间区分(类似jav ...

  3. SORM框架01

    架构图 Query接口:负责查询(对外提供的核心服务类) QueryFactory类:负责根据配置信息创建Query对象 TypeConvertor接口:类型转换 TableContext类:负责获取 ...

  4. 微信小程序云开发|Error: ResourceNotFound.FunctionName, FunctionName 指定的资源不存在。 (41cd9de8-ff9b-4b1e-a65e-81ae9

    今天在上传云函数部署的时候老发现上传login 失败   ... 经过查阅资料有两种方法可行: 云函数上传后不要轻易删除!!! 1.重启客户端 2.最好的解决方法在云平台开发创建一个新的云函数覆盖就o ...

  5. Vue.js-Vue的初体验

    我是参考https://www.cnblogs.com/kidney/p/6052935.html 这位大神的 最开始接触vue的时候,是他的input框输入的文字和旁边的span展示的文字同步,当时 ...

  6. Atcoder Beginner Contest 166

    VP赛况如下: 前言:感觉这一场题目难度还是比较贴近新生的,我一个codeforces小蓝名一小时居然AK了,F题数据有点水(?)暴力dfs居然都能过... A:A?C 题意:给你字符串,如果字符串是 ...

  7. 如何在一台计算机上安装多个 JDK 版本

    前言 对于使用 Java 语言开发的朋友可能会遇到这种情况,有时想学习和探索 Java 的最新版本提供的一些新特性,比如 Java 11,但你无法将其安装在自己的计算机上,因为你的团队正在使用比这个旧 ...

  8. 黑马程序员_毕向东_Java基础视频教程——三元运算符(随笔)

    三元运算符:三个元素参与运算的符号 [三元运算符:简略版的 if(){} else() {}语句] class Text { public static void main(String[] args ...

  9. quartzJob

    定时任务的时间修改.暂停.立即执行 定时任务的修改.暂停主要是调用quartz内置方法pauseJob().resumeJob().triggerJob()等方法 //暂停一个job JobKey j ...

  10. 给DataTable添加行的几种方式

    最近做项目的时候遇到向已有Table中添加另外一个Table中的某一行数据.我是采用这样思路做的: DataTable dtSource = xxxx;//获得的数据源 DataTable dtTar ...