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.
Input:
s = "abcd"
t = "abcde"
Output:
e
Explanation:
'e' is the letter that was added.
char findTheDifference(char* s, char* t)
{
int i = 0;
int hash[26] = {0};
for(i = 0;(s[i] != '\0') && (t[i] != '\0');i++)
{
hash[s[i] - 'a'] -= 1;
hash[t[i] - 'a'] += 1;
}
hash[t[i] - 'a'] += 1;
for(i = 0;i < 26;i++)
{
if(hash[i] == 1)
{
break;
}
}
return 'a' + i;
}