###### 【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.

c++代码（22ms）

class Solution {
public:
char findTheDifference(string s, string t) {
int len1=s.length();
int len2=t.length();
string str1,str2;  //str1存长的字符串
if(len1>len2){
str1 = s;
str2 = t;
}else{
str1 = t;
str2 = s;
}//if

map<char, int> a;
for(int i=0; i<s.length(); i++){
a[s[i]]++;
}//for
for(int i=0; i<t.length(); i++){
a[t[i]]--;
}
map<char, int>::iterator it;
for(it=a.begin(); it!=a.end(); it++){
if(it->second){
return (it->first);
}
}//for
return 'c';
}
};

c++代码（4ms）

class Solution {
public:
char findTheDifference(string s, string t) {
char result=0;
for(char c:s) result^=c;
for(char c:t) result^=c;
return result;
}
};

#### leetcode 389 Find the Difference C++

2016-08-31 19:56:18

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

2016-08-29 14:10:50

#### LeetCode : 389. Find the Difference

2016-08-29 17:02:16

#### 【python】【leetcode】【算法题目389—Find the Difference】

2016-12-04 12:03:33

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

2016-09-06 11:48:56

#### leetcode_389 Find the Difference

2016-08-29 20:37:18

#### 【LeetCode-389】Find the Difference(C++)

2016-09-02 17:00:03

#### 389. Find the Difference的C++解法

2017-03-31 11:05:13

#### 389. Find the Difference Add to List(新添字符)

2017-04-01 22:34:17

#### 389. Find the Difference | 找字符串中的不同

2017-02-11 15:52:56

## 不良信息举报

【leetcode】389. Find the Difference