18 lines
582 B
Python
18 lines
582 B
Python
# https://leetcode.com/problems/sort-the-jumbled-numbers
|
|
from typing import List
|
|
|
|
class Solution:
|
|
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
|
|
def convert(val: int) -> int:
|
|
ret = 0
|
|
base = 1
|
|
while val >= 10:
|
|
ret += mapping[val % 10] * base
|
|
base *= 10
|
|
val //= 10
|
|
ret += mapping[val % 10] * base
|
|
return ret
|
|
return [
|
|
nums[i] for i in sorted(range(len(nums)),
|
|
key=lambda i: (convert(nums[i]), i))
|
|
]
|