1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-10-18 06:42:08 +02:00
LeetCode/cs/rank-transform-of-an-array.cs
Matej Focko 9c8e14695c
cs: add «1331. Rank Transform of an Array»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-10-02 21:22:03 +02:00

14 lines
394 B
C#

public class Solution {
public int[] ArrayRankTransform(int[] arr) {
var unique = new SortedSet<int>();
foreach (var x in arr) {
unique.Add(x);
}
var ranks = unique.Select((item, index) => (item, index + 1)).ToDictionary();
for (int i = 0; i < arr.Length; ++i) {
arr[i] = ranks[arr[i]];
}
return arr;
}
}