Java实现 LeetCode 728 自除数(暴力)
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 自除数(暴力)的更多相关文章
- LeetCode 728. 自除数
题目链接:https://leetcode-cn.com/problems/self-dividing-numbers/ 给定上边界和下边界数字,输出一个列表,列表的元素是边界(含边界)内所有的自除数 ...
- C# 刷遍 Leetcode 面试题系列连载(3): No.728 - 自除数
前文传送门: C#刷遍Leetcode面试题系列连载(1) - 入门与工具简介 C#刷遍Leetcode面试题系列连载(2): No.38 - 报数 系列教程索引 传送门:https://enjoy2 ...
- 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 ...
- Java for LeetCode 044 Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single character. ...
- 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 ...
- 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. ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- asp.net mvc entityframework sql server 迁移至 mysql方法以及遇到的问题
背景: 我原来的项目是asp.net mvc5 + entityframework 6.4 for sql server(localdb,sql server),现在需要把数据库切换成mysql,理论 ...
- quartus ii FFT核使用
quartus ii FFT核使用 导入自己程序自带的txt文件,写出控制模块 时序图 FFT核文件给出的时序图输入 仿真时序图 1024个采样点数,输入结束 fft数据输出 2.代码 `timesc ...
- Android平台使用termux,随时随地写代码
生活如此无聊,写点代码打发时间. 趁着假期,我的vivo手机和华为平板(均为4G+64G配置)用的也比较少.于是,思考着如何将这2个设备用来写latex.python.用kingroot却取不了两设备 ...
- python基础学习笔记(纸质)
大一的时候学的python做的笔记.
- CQengine高性能内存数据缓存查找框架
CQengine可实现高性能内存数据缓存查找 CQEngine 需要设置字段对应的属性以方便访问与查询 主要有属性链接 SimpleAttribute(不能为空) SimpleNullableAttr ...
- 「雕爷学编程」Arduino动手做(13)——触摸开关模块
37款传感器和模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器与模块,依照实践出真知(动手试试)的理念,以学习和交流为目的,这里准备 ...
- Java Thread中,run方法和start方法的区别
两种方法的区别: 1.start方法 用 start方法来启动线程,是真正实现了多线程, 通过调用Thread类的start()方法来启动一个线程,这时此线程处于就绪(可运行)状态,并没有运行,一旦 ...
- HTML标签和属性二
五.文本标记 7.文本样式 <b></b> <strong></strong> 加粗 <i></i> <em> ...
- drf 生命周期
1) 根据应用中urls.py,走as_view方法,但是视图类没有该方法,所以请求走的是APIView的as_view方法 2) 在APIView的as_view调用父类(django原生View) ...
- 索引 'GXHRCS.PK_A253' 或这类索引的分区处于不可用状态
ORA-01502: 索引 'GXHRCS.PK_A253' 或这类索引的分区处于不可用状态 http://blog.sina.com.cn/s/blog_7ab8d2720101ozw6.html ...