Skip to content

Commit 94d4dd4

Browse files
author
Mykyta Mykhailenko
committed
add height checker solution
1 parent 9e81108 commit 94d4dd4

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
3+
namespace LeetCodeResolves.Arrays.HeightChecker
4+
{
5+
public class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
var heights = new int[] { 1, 1, 4, 2, 1, 3 };
10+
var result = HeightChecker(heights);
11+
12+
Console.ReadLine();
13+
}
14+
15+
static int HeightChecker(int[] heights)
16+
{
17+
var expected = new int[heights.Length];
18+
for(var i = 0; i < heights.Length; i++)
19+
{
20+
expected[i] = heights[i];
21+
}
22+
23+
Array.Sort(expected);
24+
25+
var count = 0;
26+
for(var i = 0; i< heights.Length; i++)
27+
{
28+
if(heights[i] != expected[i])
29+
{
30+
count++;
31+
}
32+
}
33+
34+
35+
return count;
36+
}
37+
}
38+
}

C#/LeetCodeResolves/LeetCodeResolves/LeetCodeResolves.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
6-
<StartupObject>LeetCodeResolves.Arrays.SortByParity.Program</StartupObject>
6+
<StartupObject>LeetCodeResolves.Arrays.HeightChecker.Program</StartupObject>
77
</PropertyGroup>
88

99
</Project>

0 commit comments

Comments
 (0)