/* 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; }
389.Find the Difference
原创
©著作权归作者所有:来自51CTO博客作者jenslee的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
LeetCode之Find the Difference
1、题目Given two stringssandtwhich consist of only lowercase letters.Stringtis generated by random shuffling stringsand the
LeetCode Find the Difference i++ 字符串 数据