Solution:
思路:添加不同字符到s再与t比较
char findTheDifference(string s, string t) {
if(s.empty()){
return t[0];
}
string ss;
for(int i = 0; i<26; i++) {
ss = s;
ss.resize(t.size(),(char)('a'+i));
sort(ss.begin(),ss.end());
sort(t.begin(),t.end());
// cout<<ss<<", "<<t<<" "<<(char)('a'+i)<<endl;
if(t==ss) {
// cout<<ss<<", "<<t<<" "<<(char)('a'+i)<<endl;
return (char)('a'+i);
}
}
}
思路:编码解码的思想
char findTheDifference(string s, string t) {
char r=0;
for(char c:s) r ^=c;
for(char c:t) r ^=c;
return r;
}