Sort the Jumbled Numbers

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
class Solution:
    def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
        def convert(num: int) -> int:
            if num == 0:
                return mapping[0]
            n, f = 0, 1
            while num > 0:
                num, r = divmod(num, 10)
                n += mapping[r] * f
                f *= 10
            return n

        indices = sorted(range(len(nums)), key=lambda i: convert(nums[i]))
        return [nums[i] for i in indices]