Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaed69e7

Browse files
committed
fix: forgot commit the "Find the Difference"
1 parent1a3bf58 commitaed69e7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
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+
classSolution {
28+
public:
29+
charfindTheDifference(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)

[8]ページ先頭

©2009-2025 Movatter.jp