class Solution {
public:
char findTheDifference(string s, string t) {
int i,l;
int record[26];
for(i = 0;i<26;i++)
{
record[i] = 0;
}
l = s.length();
for(i = 0;i<l;i++)
{
record[s[i] - 'a']++;
}
l = t.length();
for(i = 0;i<l;i++)
{
record[t[i] - 'a']--;
}
for(i = 0;i<26;i++)
{
if(record[i] == -1)
{
return char('a' + i);
}
}
return ' ';
}
};
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.