Skip to content

Commit 49e3b3a

Browse files
committed
fix: forgot commit the "Find the Difference"
1 parent fe2be99 commit 49e3b3a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Source : https://leetcode.com/problems/find-the-difference/
2+
// Author : Hao Chen
3+
// Date : 2016-09-08
4+
5+
/***************************************************************************************
6+
*
7+
* Given two strings s and t which consist of only lowercase letters.
8+
*
9+
* String t is generated by random shuffling string s and then add one more letter at a
10+
* random position.
11+
*
12+
* Find the letter that was added in t.
13+
*
14+
* Example:
15+
*
16+
* Input:
17+
* s = "abcd"
18+
* t = "abcde"
19+
*
20+
* Output:
21+
* e
22+
*
23+
* Explanation:
24+
* 'e' is the letter that was added.
25+
***************************************************************************************/
26+
27+
class Solution {
28+
public:
29+
char findTheDifference(string s, string t) {
30+
unordered_map<char, int> m;
31+
for(auto c : s) m[c]++;
32+
for(auto c : t) {
33+
m[c]--;
34+
if (m[c] < 0) return c;
35+
}
36+
return '\0';
37+
}
38+
};

0 commit comments

Comments
 (0)