给定两个只包含小写字母的字符串 s 和 t 。
字符串 t 是由随机打乱字符顺序的字符串 s 在随机位置添加一个字符生成。
找出在 t 中添加的字符。
样例:
输入:s = "abcd",t = "abcde"
输出:'e'
解释:'e' 是字符串t与字符串s相比较,新加入的字符.
class Solution {
public:
/**
* @param s: a string
* @param t: a string
* @return: the letter that was added in t
*/
char findTheDifference(string &s, string &t) {
// Write your code here
sort(s.begin(),s.end());
sort(t.begin(),t.end());
for (int i = 0; i < t.size(); i++) {
/* code */
if(t[i]!=s[i]) return t[i];
}
}
};