-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path811.cpp
More file actions
23 lines (23 loc) · 860 Bytes
/
Copy path811.cpp
File metadata and controls
23 lines (23 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
vector<string> subdomainVisits(vector<string> &cpdomains) {
unordered_map<string, int> visit;
for (auto current: cpdomains) {
int space = current.find(" ");
int num = stoi(current.substr(0, space));
current = current.substr(space + 1, current.size());
int start = -1;
do {
current = current.substr(start + 1, current.size());
if (visit.find(current) == visit.end())
visit.insert(pair<string, int>(current, num));
else
visit[current] += num;
} while ((start = current.find(".")) != string::npos);
}
vector<string> ret;
for (auto v : visit)
ret.push_back(to_string(v.second) + " " + v.first);
return ret;
}
};