题目分析:
将两个字符串按照字母序进行排序,然后从头开始遍历,找出第一个不相等的元素即为所求。
class Solution {
public:
char findTheDifference(string s, string t) {
sort(s.begin(),s.end());
sort(t.begin(),t.end());
int i=0;
while(s[i]==t[i]){
i++;
}
return t[i];
}
};