Skip to content

Commit de858a7

Browse files
committed
Remove duplicates from array
1 parent 6bbfa97 commit de858a7

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29403.142
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodingInterview", "CodingInterview\CodingInterview.csproj", "{CCF14D57-7B3C-4A45-BE01-7299839BD250}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{CCF14D57-7B3C-4A45-BE01-7299839BD250}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CCF14D57-7B3C-4A45-BE01-7299839BD250}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CCF14D57-7B3C-4A45-BE01-7299839BD250}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CCF14D57-7B3C-4A45-BE01-7299839BD250}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {1866F9A6-6337-4F74-A927-B48117CD3C6A}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="nunit" Version="3.12.0" />
11+
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using NUnit.Framework;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace CodingInterview
6+
{
7+
public class Tests
8+
{
9+
int[] RemoveDuplicates(int[] arrayOfNumbers)
10+
{
11+
var numbers = new HashSet<int>();
12+
for(int index = 0; index < arrayOfNumbers.Length; index++)
13+
{
14+
numbers.Add(arrayOfNumbers[index]);
15+
}
16+
return numbers.ToArray();
17+
}
18+
19+
[Test]
20+
public void RemoveDuplicatesFromSortedArray_1()
21+
{
22+
var sortedArrayWithDuplicates = new int[] { 1, 3, 3, 6, 8, 8, 9 };
23+
var expectedSortedArrayWithoutDuplicates = new int[] { 1, 3, 6, 8, 9 };
24+
25+
var sortedArrayWithoutDuplicatesCalculated = RemoveDuplicates(sortedArrayWithDuplicates);
26+
27+
Assert.AreEqual(expectedSortedArrayWithoutDuplicates, sortedArrayWithoutDuplicatesCalculated);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)