-
Notifications
You must be signed in to change notification settings - Fork 112
/
1291-SequentialDigits.cs
31 lines (28 loc) · 1 KB
/
1291-SequentialDigits.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
//-----------------------------------------------------------------------------
// Runtime: 204ms
// Memory Usage: 25.3 MB
// Link: https://leetcode.com/submissions/detail/399385446/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _1291_SequentialDigits
{
public IList<int> SequentialDigits(int low, int high)
{
var sample = "123456789";
int n = 10;
var results = new List<int>();
int lowLen = low.ToString().Length;
int highLen = high.ToString().Length;
for (int length = lowLen; length < highLen + 1; length++)
for (int start = 0; start < n - length; start++)
{
int num = int.Parse(sample.Substring(start, length));
if (num >= low && num <= high)
results.Add(num);
}
return results;
}
}
}