-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution728.cs
43 lines (36 loc) · 878 Bytes
/
Solution728.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
40
41
42
43
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution728
{
/// <summary>
/// 728. Self Dividing Numbers - Easy
/// <a href="https://leetcode.com/problems/self-dividing-numbers">See the problem</a>
/// </summary>
public IList<int> SelfDividingNumbers(int left, int right)
{
var result = new List<int>();
for (var i = left; i <= right; i++)
{
if (IsSelfDividing(i))
{
result.Add(i);
}
}
return result;
}
private bool IsSelfDividing(int num)
{
var n = num;
while (n > 0)
{
var digit = n % 10;
if (digit == 0 || num % digit != 0)
{
return false;
}
n /= 10;
}
return true;
}
}