-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
29 lines (28 loc) · 722 Bytes
/
Solution.cs
File metadata and controls
29 lines (28 loc) · 722 Bytes
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
public class Solution
{
public int HeightChecker(int[] heights)
{
int n = heights.Length;
int[] expected = new int[n];
Array.Copy(heights, expected, n);
bool hasSwap = true;
while (hasSwap)
{
hasSwap = false;
for (int i = 0; i < n - 1; i++)
{
if (expected[i] > expected[i + 1])
{
(expected[i], expected[i + 1]) = (expected[i + 1], expected[i]);
hasSwap = true;
}
}
}
int ret = 0;
for (int i = 0; i < n; i++)
{
if (heights[i] != expected[i]) ret++;
}
return ret;
}
}