#Leetcode# 728. Self Dividing Numbers
阿新 • • 發佈:2019-04-12
each bounds highlight right self ack ext numbers family
https://leetcode.com/problems/self-dividing-numbers/
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
.
代碼:
class Solution { public: vector<int> selfDividingNumbers(int left, int right) { vector<int> ans; for(int i = left; i <= right; i ++) { if(iself(i)) ans.push_back(i); } return ans; } bool iself(int x) { int y = x; while(x) { if(x % 10 == 0) return false; if(y % (x % 10)) return false; x /= 10; } return true; } };
今天 LeetCode 五題打卡 杭州陰天三天之後天氣終於放晴 準備提前回去跑步啦 被 extgcd 搞得一天沒有好心情了 晚上回去多學一會吧
@fh
#Leetcode# 728. Self Dividing Numbers