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


	public char findTheDifference(String s, String t) {
char c = 0;
for (char a : s.toCharArray()) a^=c;
for (char b : t.toCharArray()) b^=c;
return (char) c;
}


	public char findTheDifference(String s, String t) {
char[] count = new char[26];
for (char c : s.toCharArray()) count[c - 97]++;
for (char c : t.toCharArray()) if (count[c - 97]-- < 1) return c;
return 'a';
}


• 本文已收录于以下专栏：

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

389. Find the DifferenceGiven two strings s and t which consist of only lowercase letters. String t...

## [LeetCode]242.Valid Anagram&383. Ransom Note&389. Find the Difference

242.Valid Anagram 383. Ransom Note 389. Find the Difference

## leetcode389. Find the Difference

389. Find the DifferenceGiven two strings s and t which consist of only lowercase letters.String t i...

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

Given two strings s and t which consist of only lowercase letters. String t is generated by random s...

## 【LeetCode】389 Find the Difference（java）

• styshoo
• 2016年09月29日 23:46
• 508

## Tutorial: 389. Find the Difference

LeetCode算法题：389. Find the Difference的解法。
• atmiao
• 2016年12月26日 22:18
• 147

## 389. Find the Difference [easy] (Python)

举报原因： 您举报文章：LeetCode 389 Find the Difference 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)