MCPcopy Create free account
hub / github.com/ROUTINE-STUDY/Algorithm / Sanghoo

Class Sanghoo

LeetCode/Array/1122. Relative Sort Array/Sanghoo.java:10–36  ·  view source on GitHub ↗

https://leetcode.com/problems/relative-sort-array/

Source from the content-addressed store, hash-verified

8 * https://leetcode.com/problems/relative-sort-array/
9 */
10public class Sanghoo {
11
12 public int[] relativeSortArray(int[] arr1, int[] arr2) {
13 List<Integer> list = new ArrayList<>();
14
15 for(int a2 : arr2) {
16 for(int i = 0 ; i < arr1.length; i++) {
17 if(arr1[i] == a2) {
18 list.add(arr1[i]);
19 arr1[i] = -1;
20 }
21 }
22 }
23 Arrays.sort(arr1);
24 for(int i=list.size(); i < arr1.length; i++) {
25 list.add(arr1[i]);
26 }
27
28 for(int i=0; i<list.size(); i++) {
29 arr1[i] = list.get(i);
30 }
31
32 return arr1;
33// return list.stream().mapToInt(Integer::intValue).toArray();
34 }
35
36}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected