-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path884.cpp
More file actions
29 lines (28 loc) · 802 Bytes
/
Copy path884.cpp
File metadata and controls
29 lines (28 loc) · 802 Bytes
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
class Solution {
public:
vector<string> uncommonFromSentences(string A, string B) {
unordered_map<string, int> sentences;
vector<string> ret;
Traversal(A, sentences);
Traversal(B, sentences);
for (auto s:sentences) {
if (s.second == 1)
ret.push_back(s.first);
}
return ret;
}
void Traversal(string &S, unordered_map<string, int> &sentences) {
while (!S.empty()) {
int pos = S.find(" ");
if (pos != S.npos) {
string &&temp = S.substr(0, pos);
++sentences[temp];
S = S.substr(pos + 1, S.size() - pos);
} else {
++sentences[S];
S = "";
}
}
return;
}
};