Content-Length: 463110 | pFad | http://github.com/BigEggStudy/LeetCode-CS/commit/3eb2d774c93effcc0b1233c814279822169d9bad

C5 Add solution for problem 1291 · BigEggStudy/LeetCode-CS@3eb2d77 · GitHub
Skip to content

Commit 3eb2d77

Browse files
committed
Add solution for problem 1291
1 parent 890ddf5 commit 3eb2d77

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace LeetCode.Test
4+
{
5+
[TestClass]
6+
public class _1291_SequentialDigits_Test
7+
{
8+
[TestMethod]
9+
public void SequentialDigits_1()
10+
{
11+
var solution = new _1291_SequentialDigits();
12+
var result = solution.SequentialDigits(100, 300);
13+
AssertHelper.AssertList(new int[] { 123, 234 }, result);
14+
}
15+
16+
[TestMethod]
17+
public void SequentialDigits_2()
18+
{
19+
var solution = new _1291_SequentialDigits();
20+
var result = solution.SequentialDigits(1000, 13000);
21+
AssertHelper.AssertList(new int[] { 1234, 2345, 3456, 4567, 5678, 6789, 12345 }, result);
22+
}
23+
}
24+
}

LeetCode.Test/LeetCode.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@
768768
<Compile Include="1251-1300\1286-IteratorForCombination-Test.cs" />
769769
<Compile Include="1251-1300\1287-ElementAppearingMoreThan25InSortedArray-Test.cs" />
770770
<Compile Include="1251-1300\1290-ConvertBinaryNumberInALinkedListToInteger-Test.cs" />
771+
<Compile Include="1251-1300\1291-SequentialDigits-Test.cs" />
771772
<Compile Include="1251-1300\1295-FindNumbersWithEvenNumberOfDigits-Test.cs" />
772773
<Compile Include="1251-1300\1296-DivideArrayInSetsOfKConsecutiveNumbers-Test.cs" />
773774
<Compile Include="1251-1300\1299-ReplaceElementsWithGreatestElementOnRightSide-Test.cs" />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//-----------------------------------------------------------------------------
2+
// Runtime: 204ms
3+
// Memory Usage: 25.3 MB
4+
// Link: https://leetcode.com/submissions/detail/399385446/
5+
//-----------------------------------------------------------------------------
6+
7+
using System.Collections.Generic;
8+
9+
namespace LeetCode
10+
{
11+
public class _1291_SequentialDigits
12+
{
13+
public IList<int> SequentialDigits(int low, int high)
14+
{
15+
var sample = "123456789";
16+
int n = 10;
17+
var results = new List<int>();
18+
19+
int lowLen = low.ToString().Length;
20+
int highLen = high.ToString().Length;
21+
for (int length = lowLen; length < highLen + 1; length++)
22+
for (int start = 0; start < n - length; start++)
23+
{
24+
int num = int.Parse(sample.Substring(start, length));
25+
if (num >= low && num <= high)
26+
results.Add(num);
27+
}
28+
return results;
29+
}
30+
}
31+
}

LeetCode/LeetCode.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@
762762
<Compile Include="1251-1300\1286-IteratorForCombination.cs" />
763763
<Compile Include="1251-1300\1287-ElementAppearingMoreThan25InSortedArray.cs" />
764764
<Compile Include="1251-1300\1290-ConvertBinaryNumberInALinkedListToInteger.cs" />
765+
<Compile Include="1251-1300\1291-SequentialDigits.cs" />
765766
<Compile Include="1251-1300\1295-FindNumbersWithEvenNumberOfDigits.cs" />
766767
<Compile Include="1251-1300\1296-DivideArrayInSetsOfKConsecutiveNumbers.cs" />
767768
<Compile Include="1251-1300\1299-ReplaceElementsWithGreatestElementOnRightSide.cs" />

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[![AppVeyor Build Status](https://img.shields.io/appveyor/build/bigegg/leetcode-cs?label=Windows%20Build%20Status&logo=AppVeyor&style=flat-square)](https://ci.appveyor.com/project/BigEgg/leetcode-cs)
2-
[![Solved Problems](https://img.shields.io/badge/Solved%20Problems-813-blue.svg?style=flat-square)](https://github.com/BigEggStudy/LeetCode-CS)
2+
[![Solved Problems](https://img.shields.io/badge/Solved%20Problems-814-blue.svg?style=flat-square)](https://github.com/BigEggStudy/LeetCode-CS)
33

44
# LeetCode
55
The C# solutions for LeetCode problems.
@@ -911,6 +911,7 @@ The C# solutions for LeetCode problems.
911911
| 1286 | Iterator for Combination | [C#](./LeetCode/1251-1300/1286-IteratorForCombination.cs)(120ms) | O(K) | O(K) | |
912912
| 1287 | Element Appearing More Than 25% In Sorted Array | [C#](./LeetCode/1251-1300/1287-ElementAppearingMoreThan25InSortedArray.cs)(96ms) | O(N) | O(1) | |
913913
| 1290 | Convert Binary Number in a Linked List to Integer | [C#](./LeetCode/1251-1300/1290-ConvertBinaryNumberInALinkedListToInteger.cs)(84ms) | O(N) | O(1) | |
914+
| 1291 | Sequential Digits | [C#](./LeetCode/1251-1300/1291-SequentialDigits.cs)(204ms) | O(1) | O(1) | |
914915
| 1295 | Find Numbers with Even Number of Digits | [C#](./LeetCode/1251-1300/1295-FindNumbersWithEvenNumberOfDigits.cs)(92ms) | O(N) | O(N) | |
915916
| 1296 | Divide Array in Sets of K Consecutive Numbers | [C#](./LeetCode/1251-1300/1296-DivideArrayInSetsOfKConsecutiveNumbers.cs)(592ms) | O(NlogN) | O(N) | |
916917
| 1299 | Replace Elements with Greatest Element on Right Side | [C#](./LeetCode/1251-1300/1299-ReplaceElementsWithGreatestElementOnRightSide.cs)(264ms) | O(N) | O(1) | |

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/BigEggStudy/LeetCode-CS/commit/3eb2d774c93effcc0b1233c814279822169d9bad

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy