# 原题

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.

# 解法

public char findTheDifference(String s, String t) {
int[] nums = new int[26];
for (int i = 0; i < s.length(); i++) {
char ch = s.charAt(i);
++nums[ch - 'a'];
}
char ret = 'a';
for (int i = 0; i < t.length(); i++) {
char ch = t.charAt(i);
--nums[ch - 'a'];
if (nums[ch - 'a'] < 0) {
ret = ch;
break;
}
}
return ret;
}

public char findTheDifference(String s, String t) {
int ret = 0;
for (int i = 0; i < s.length(); i++) {
ret -= (int)s.charAt(i);
}
for (int i = 0; i < t.length(); i++) {
ret += (int)t.charAt(i);
}
return (char)ret;
}

public char findTheDifference(String s, String t) {
int ret = 0;
for (int i = 0; i < s.length(); i++) {
ret ^= s.charAt(i);
}
for (int i = 0; i < t.length(); i++) {
ret ^= t.charAt(i);
}
return (char)ret;
}