Leetcode Problem 2191. Sort the Jumbled Numbers

2191. Sort the Jumbled Numbers

Leetcode Solutions

Mapping and Sorting with Stability

  1. Create a list to hold tuples, where each tuple contains the original number and its mapped value.
  2. Iterate over each number in nums.
    • Convert the number to a string to access individual digits.
    • Map each digit according to the mapping array and form the mapped number.
    • Append a tuple of the original number and the mapped number to the list.
  3. Sort the list of tuples based on the mapped values (second element of the tuple).
  4. Extract the original numbers from the sorted list of tuples and return them as the result.
UML Thumbnail

Mapping and Custom Sort Function

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...