# [leetcode] 389. Find the Difference 解题报告

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.

class Solution {
public:
char findTheDifference(string s, string t) {
unordered_map<char, int> hash;
char ans;
for(auto ch: s) hash[ch]++;
for(auto ch: t)
if(--hash[ch]<0) ans = ch;
return ans;
}
};

class Solution {
public:
char findTheDifference(string s, string t) {
s += t;
int ch =0;
for(auto val: s) ch ^= val;
return ch;
}
};

#### leetcode算法——389. Find the Difference(基于JAVA)

2016-09-06 11:48:56

#### leetcode_389 Find the Difference

2016-08-29 20:37:18

#### Find the Difference问题及解法

2017-04-11 08:54:01

#### 389. Find the Difference

2017-03-26 23:27:15

#### LeetCode389. Find the Difference

2016-08-29 10:26:26

#### LeetCode : 389. Find the Difference

2016-08-29 17:02:16

#### Leetcode 389. Find the Difference 找不同 解题报告

2016-08-29 16:57:16

#### leetcode389python 找不同

2018-05-22 14:43:42

#### Leetcote 389. 找不同

2018-05-18 17:06:13

#### [LeetCode]389. Find the Difference(找不同)

2017-03-12 18:15:29