1122. Relative Sort Array

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1122

class Solution:
    def relativeSortArray(self, arr1: List[int], arr2: List[int]) -> List[int]:
        pos = {x: i for i, x in enumerate(arr2)}
        return sorted(arr1, key=lambda x: pos.get(x, 1000 + x))