Untitled

 avatar
unknown
c_cpp
a year ago
698 B
6
Indexable
class Solution {
public:
    
    struct cmp{
        unordered_map<int,int> mp;
        bool operator()(const int &x, const int &y){
            return mp[x]<mp[y];
        }
    };

    vector<int> sortJumbled(vector<int>& mapping, vector<int>& nums) {
        cmp temp;
        for(auto i:nums){
            if(i==0){
                temp.mp[0]=mapping[0];
                continue;
            }
            int x=i; int cnt=1,res=0;
            while(x){
                int y=x%10;
                x/=10;
                res+=cnt*mapping[y];
                cnt*=10;
            }
            temp.mp[i]=res;
        }
        sort(nums.begin(),nums.end(),temp);
        return nums;
    }
};
Editor is loading...
Leave a Comment