// 389. Find the Difference #include /* * given two strings 's' and 't'. string 't' is generated by random shuffling * string 's' and then add one more letter at a random position. return the * letter that was added to 't'. */ char findTheDifference(char *s, char *t) { char ans = 0; while (*s != '\0') { ans ^= (*s) ^ (*t); ++s; ++t; } return ans ^ (*t); } int main() { char s1[] = {"abcd"}, t1[] = {"abcde"}; char s2[] = {""}, t2[] = {"y"}; printf("%c\n", findTheDifference(s1, t1)); // expect: e printf("%c\n", findTheDifference(s2, t2)); // expect: y }