forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cs
32 lines (30 loc) · 843 Bytes
/
Solution.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
public class Solution {
public int[] SortJumbled(int[] mapping, int[] nums) {
Func<int, int> f = (int x) => {
if (x == 0) {
return mapping[0];
}
int y = 0;
int k = 1;
int num = x;
while (num != 0) {
int v = mapping[num % 10];
y = k * v + y;
k *= 10;
num /= 10;
}
return y;
};
int n = nums.Length;
List<(int, int)> arr = new List<(int, int)>();
for (int i = 0; i < n; ++i) {
arr.Add((f(nums[i]), i));
}
arr.Sort();
int[] ans = new int[n];
for (int i = 0; i < n; ++i) {
ans[i] = nums[arr[i].Item2];
}
return ans;
}
}