LeetCode Self Dividing Numbers
来源:互联网 发布:雪梨开的淘宝店店名 编辑:程序博客网 时间:2024/05/29 14:27
A 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 == 0, 128 % 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.
Note:
The boundaries of each input argument are 1 <= left <= right <= 10000.
自除数:这个数可以整除他包含的每个数字
eg: 128。128除以1,2,8都能整除
自除数要求不能包含0
求解包含左右边界在内的所有自除数
class Solution { public List<Integer> selfDividingNumbers(int left, int right) { int temp=0; int sub=0; List<Integer> result = new ArrayList<Integer>(); for(int i=left; i<=right; i++){ temp = i/10; sub = i%10; while(temp>0){ if(sub !=0 && i%sub == 0){ sub = temp%10; temp = temp/10; }else{ break; } } if(temp == 0 && sub != 0 && i%sub == 0){ result.add(i); } } return result; }}
阅读全文
0 0
- Self Dividing Numbers(leetcode)
- LeetCode Self Dividing Numbers
- 【LeetCode】728. Self Dividing Numbers
- 【LeetCode】728. Self Dividing Numbers
- leetcode-728. Self Dividing Numbers
- LeetCode.728 Self Dividing Numbers
- leetcode 728. Self Dividing Numbers
- Leetcode:728. Self Dividing Numbers
- LeetCode 728. Self Dividing Numbers
- [LeetCode] 728.Self Dividing Numbers
- LeetCode 728. Self Dividing Numbers
- [LeetCode]728. Self Dividing Numbers
- LeetCode | 728. Self Dividing Numbers
- [LeetCode] 728. Self Dividing Numbers
- Leetcode——728. Self Dividing Numbers
- LeetCode 728. Self Dividing Numbers with Java
- [Leetcode从零开刷]728. Self Dividing Numbers
- 728. Self Dividing Numbers
- 论为什么需要软件工程
- Educational Codeforces Round 34
- 商品列表(MVp)
- 【cuda】This graphics driver could not find compatible graphics hardware..
- -bash: rvm: command not found'
- LeetCode Self Dividing Numbers
- 机器学习之贝叶斯分类器
- ElasticSearch Java客户端简易使用教程
- C++浅析operator运算符重载
- Ubuntu16.04 安装Nvidia显卡
- 我决定现在要专心的去学习java、c#及相关技术了
- [BZOJ3489]A simple rmq problem(KD-tree||主席树+KD-tree小结)
- 百度富文本编辑器UMeditor的使用
- 最简单最规范的判断,String内是否包含中文