luoheng
10/11/2019 - 7:37 AM

relativeSortArray

func relativeSortArray(arr1 []int, arr2 []int) []int {
    arr3 := [1001]int{}
    for _, a := range arr1 {
        arr3[a]++
    }
    res := make([]int, 0, len(arr1))
    for _, a := range arr2 {
        for arr3[a] != 0 {
            res = append(res, a)
            arr3[a]--
        }
    }
    for i, a := range arr3 {
        for a != 0 {
            res = append(res, i)
            a--
        }
    }
    return res
}