char findTheDifference(string s, string t) {
unordered_map<char,int> m;
for(auto a:s) m[a]++;
for(auto a:t)
if(m[a]--<1)
return a;
return 0;
}
利用异或,相同的抵消,结果为添加的字符
char findTheDifference(string s, string t) {
char res=0;
for(auto a:s) res^=a;
for(auto a:t) res^=a;
return res;
}
也可以用加减,剩下的为加上的
char findTheDifference(string s, string t) {
char res=0;
for(auto a:s) res-=a;
for(auto a:t) res+=a;
return res;
}
char findTheDifference(string s, string t) {
return accumulate(begin(s),end(s+=t),0,bit_xor<int>());
}