原题:
Given two strings s and t which consist of only lowercase letters.
String t is generated by random shuffling string s and then add one more letter at a random position.
Find the letter that was added in t.
C++解法:
char findTheDifference(string s, string t) {
if(s.empty())
return t[0];
string a = s+t;
char res = a[0];;
for(string::size_type i = 1; i!=a.size();++i)
res = res^a[i];
return res;
}
本文介绍了一种使用C++编程语言解决特定字符串问题的方法:通过异或操作高效找出经打乱并添加了一个字母后的字符串中新增的字母。
363

被折叠的 条评论
为什么被折叠?



