-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution1122.cs
41 lines (35 loc) · 885 Bytes
/
Solution1122.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
32
33
34
35
36
37
38
39
40
41
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution1122
{
/// <summary>
/// 1122. Relative Sort Array - Easy
/// <a href="https://leetcode.com/problems/relative-sort-array">See the problem</a>
/// </summary>
public int[] RelativeSortArray(int[] arr1, int[] arr2)
{
var count = new int[1001];
var result = new int[arr1.Length];
var index = 0;
foreach (var num in arr1)
{
count[num]++;
}
foreach (var num in arr2)
{
while (count[num]-- > 0)
{
result[index++] = num;
}
}
for (var i = 0; i < count.Length; i++)
{
while (count[i]-- > 0)
{
result[index++] = i;
}
}
return result;
}
}