//知识点:哈希-STL-unordered_map
#include<iostream>
using namespace std;
#include<string>
#include<unordered_map>
class Solution {
public:
char findTheDifference(string s, string t) {
unordered_map<int, int> hashmap;
for (char c : t) hashmap[c]++;
for (char c : s)
{
hashmap[c]--;
if (hashmap[c] == 0) hashmap.erase(c);
}
return (*hashmap.begin()).first;
}
};
void test01() {
string s = "abcd";
string t = "abcde";
Solution S;
char result = S.findTheDifference(s, t);
cout << result << endl;
}
int main()
{
test01();
system("pause");
return 0;
}
Leetcode刷题-389找不同
最新推荐文章于 2024-10-16 10:13:45 发布