1
class Solution {
2
public:
3
vector<string> subdomainVisits(vector<string> &cpdomains) {
4
vector<string> v;
5
unordered_map<string, int> m;
6
for (auto it : cpdomains) {
7
string rep = "";
8
int i = 0;
9
while (it[i] != ' ') {
10
rep += (it[i]);
11
i++;
12
}
13
int r = stoi(rep);
14
m[it.substr(i + 1, it.size())] += r;
15

16
while (it[i] != '.') {
17
i++;
18
}
19
m[it.substr(i + 1, it.size())] += r;
20
i++;
21
while (i < it.size() and it[i] != '.') {
22
i++;
23
}
24
if (i != it.size()) {
25
m[it.substr(i + 1, it.size())] += r;
26
}
27
}
28

29
for (auto it : m) {
30
string a = it.first;
31
string b = to_string(it.second);
32
a = b + " " + a;
33
v.push_back(a);
34
}
35
return v;
36
}
37
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0