3146.两个字符的排列差
题目链接:3146.两个字符的排列差
代码如下:
class Solution
{
public:
int findPermutationDifference(string s, string t)
{
unordered_map<int,vector<int>> um;
for(int i=0;i<s.size();i++)
{
um[s[i]].push_back(i);
um[t[i]].push_back(i);
}
int res=0;
for(auto it=um.begin();it!=um.end();it++)
{
res+=abs((it->second)[0]-(it->second)[1]);
}
return res;
}
};