Skip to content

Commit 366f28d

Browse files
authored
Create Solution.java
1 parent 101b3cb commit 366f28d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public int[] relativeSortArray(int[] arr1, int[] arr2) {
3+
int[] map = new int[1001];
4+
for (int x : arr1) {
5+
++map[x];
6+
}
7+
int i = 0;
8+
for (int x : arr2) {
9+
while (map[x]-- > 0) {
10+
arr1[i++] = x;
11+
}
12+
}
13+
for (int j = 0; j < map.length; ++j) {
14+
while (map[j]-- > 0) {
15+
arr1[i++] = j;
16+
}
17+
}
18+
return arr1;
19+
}
20+
}

0 commit comments

Comments
 (0)