-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (47 loc) · 1.03 KB
/
main.cpp
File metadata and controls
49 lines (47 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
// 还是异或,出现两次的一个字母
class Solution {
public:
char findTheDifference(string s, string t) {
char res = 0;
for(int i = 0; i < s.size(); ++i)
res ^= s[i];
for(int i = 0; i < t.size(); ++i)
res ^= t[i];
return res;
}
};
//map
/*
class Solution {
public:
char findTheDifference(string s, string t) {
map<char, int> mymap;
for(int i = 0; i < s.length(); ++i)
mymap[s[i]]++;
for(int i = 0; i < t.length(); ++i)
mymap[t[i]]++;
map<char, int>::iterator it;
char res;
for(it = mymap.begin(); it != mymap.end(); ++it)
{
if(it->second % 2 != 0)
res = it->first;
}
return res;
}
};
*/
int main()
{
Solution s;
string s1 = "abcd";
string s2 = "abcde";
cout << s.findTheDifference(s1, s2) << endl;
return 0;
}