leetcode 728. Self Dividing Numbers
来源:互联网 发布:nginx服务器宕机 编辑:程序博客网 时间:2024/05/19 20:47
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.
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.
思路,遍历数组,对每一个数,从低位到高位判断,用模运算%和int除法
class Solution {public: vector<int> selfDividingNumbers(int left, int right) { vector<int> result; for(int i = left; i <= right; i++) { int j = i; while(j != 0) { if ((j % 10 == 0) || (i % (j%10) != 0)) break; j = j/10; } if(j == 0) result.push_back(i); } return result; }};
阅读全文
0 0
- 【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
- Self Dividing Numbers(leetcode)
- LeetCode Self Dividing Numbers
- Leetcode——728. Self Dividing Numbers
- LeetCode 728. Self Dividing Numbers with Java
- [Leetcode从零开刷]728. Self Dividing Numbers
- 728. Self Dividing Numbers
- 728. Self Dividing Numbers
- 【思路】2.权限控制
- centos 6.8 搭建LAMP环境及配置
- 并发工具类(三)控制并发线程的数量 Semphore
- Raptor中生成任意范围的随机数
- Android自定义View——从零开始实现可暂停的旋转动画效果
- leetcode 728. Self Dividing Numbers
- laravel 课程学习系列五----------------第五章 Laravel框架常用功能
- markdown语法学习笔记
- 网络测速
- DNS服务器--正|反|双向解析、辅助dns、远程更新dns
- Microsoft.Jet.OLEDB.4.0和Microsoft.ACE.OLEDB.12.0的区别
- 汽油补给
- 精通脚本黑客2.3-2.9笔记
- 51NOD-1289-大鱼吃小鱼