forked from BigEggStudy/LeetCode-CS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0967-NumbersWithSameConsecutiveDifferences.cs
More file actions
32 lines (30 loc) · 1.05 KB
/
0967-NumbersWithSameConsecutiveDifferences.cs
File metadata and controls
32 lines (30 loc) · 1.05 KB
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
//-----------------------------------------------------------------------------
// Runtime: 208ms
// Memory Usage: 26 MB
// Link: https://leetcode.com/submissions/detail/382904466/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _0967_NumbersWithSameConsecutiveDifferences
{
public int[] NumsSameConsecDiff(int N, int K)
{
var resutls = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (int i = 2; i <= N; i++)
{
var temp = new List<int>();
foreach (var num in resutls)
{
var digit = num % 10;
if (num > 0 && K > 0 && digit - K >= 0)
temp.Add(num * 10 + digit - K);
if (num > 0 && digit + K < 10)
temp.Add(num * 10 + digit + K);
}
resutls = temp;
}
return resutls.ToArray();
}
}
}