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 ...
随机推荐
- numpy数组的分割与合并
合并 np.newaxis import numpy as np a=np.array([1,2,3])[:,np.newaxis]#变成列向量 b=np.array([4,5,6])[:,np.ne ...
- ASP.NET Core on K8S学习之旅(12)Ingress
本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章. 一.关于Ingress Kubernetes对外暴露Service主要有三种方 ...
- 阿里面试居然跟我扯了半小时的CyclicBarrier
一个大腹便便,穿着格子衬衫的中年男子,拿着一个贴满Logo的Mac向我走来,看着稀少的头发,我心想着肯定是顶级技术大牛吧!但是我也是一个才华横溢的人,稳住我们能赢. 面试官:您好,先做一下自我介绍吧! ...
- js代码中引入其他js文件
/***引入 js 文件 @example: import('js/aui.picker.js') @example: import(['js/aui.picker.js', 'css/aui.pic ...
- 2018-06-20 js字符串函数
str.length -> 字符串长度; str.indexOf() -> 从左边查找字符串中某字符的位置: str.lastIndexOf -> 从右边查找字符串中某字符的位置: ...
- mysql运维入门5:MySQL+kepalived高可用架构
keepalive 类似3/4/7层交换机制的软件,也就是平时说的第三层.第四层.第七层交换 作用是检测web服务器的状态,如果有一台web服务器.mysql服务器宕机.或工作出现故障,keepali ...
- 根据ip查询ip归属地
http://www.oschina.net/code/snippet_944819_33978 http://www.jb51.net/article/54287.htm public String ...
- jquery.autocomplete的使用-----------------------摘抄别人的
作者:lxhwss | 2011/10/11 9:46:38 | 阅读43次 document.write(”<script language=javascript src=’/js/2.js’ ...
- hdu5984概率数学
转载 https://www.oyohyee.com/post/HDU/5984.html
- UVALive5846
题目大意:见刘汝佳<算法竞赛入门经典——训练指南>P173. 解题思路: 如果要直接求所有单色三角形的个数似乎不简单,正难则反,先求出所有非单色三角形 cnt,answer = C(n,3 ...