2191. Sort the Jumbled Numbers

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

On This Page

LeetCode problem 2191

class Solution:
    def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
        arr = []
        for i, x in enumerate(nums):
            y = mapping[0] if x == 0 else 0
            k = 1
            while x:
                x, v = divmod(x, 10)
                y = mapping[v] * k + y
                k *= 10
            arr.append((y, i))
        arr.sort()
        return [nums[i] for _, i in arr]