/*
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.
Example:
Input:
s = "abcd"
t = "abcde"
Output:
e
Explanation:
'e' is the letter that was added.
*/
char findTheDifference(char* s, char* t) {
int i,j;
char add;
int n = strlen(t);
for(i = 0; i <= n-1; i++)//将相同的数都置换为1,避免遇到数组中有多个相同字母,这样可以一一对应,筛掉相同的,留下不同的
for(j=0;j<= n-2;j++)
if(t[i]==s[j])
{
t[i] = 49;
s[j] = 49;
break;
}
for(i=0;i<n;i++)//找出没有被替换的数,即多出来的数
if(t[i]!=49)
return t[i];
return;
}
还没有评论,来说两句吧...