# 2191. Sort the Jumbled Numbers ###### tags: `Leetcode` `Medium` `Sorting` Link: https://leetcode.com/problems/sort-the-jumbled-numbers/description/ ## Code ```java= class Solution { public int[] sortJumbled(int[] mapping, int[] nums) { int n = nums.length; Integer[] indices = new Integer[n]; for(int i=0; i<nums.length; i++) indices[i] = i; Arrays.sort(indices, (a,b)->(convert(nums[a], mapping)-convert(nums[b], mapping))); int[] ans = new int[n]; for(int i=0; i<nums.length; i++){ ans[i] = nums[indices[i]]; } return ans; } public int convert(int a, int[] mapping){ if(a==0) return mapping[0]; int n = 0, f = 1; while(a!=0){ n += f*mapping[a%10]; f *= 10; a /= 10; } return n; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up