-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0728-SelfDividingNumbers.cs
39 lines (33 loc) · 1.02 KB
/
0728-SelfDividingNumbers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//-----------------------------------------------------------------------------
// Runtime: 196ms
// Memory Usage: 25.7 MB
// Link: https://leetcode.com/submissions/detail/327846475/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _0728_SelfDividingNumbers
{
public IList<int> SelfDividingNumbers(int left, int right)
{
var result = new List<int>();
for (int i = left; i <= right; i++)
if (IsSelfDividing(i))
result.Add(i);
return result;
}
private bool IsSelfDividing(int num)
{
if (num > 0 && num < 9) return true;
var number = num;
while (num > 0)
{
var current = num % 10;
if ((current == 0) || (number % current != 0))
return false;
num /= 10;
}
return true;
}
}
}