leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0811.cpp (629B)


0 class Solution {
1 public:
2 vector<string> subdomainVisits(const vector<string> &cpdomains) {
3 unordered_map<string, int> um;
4 for (const auto &s : cpdomains) {
5 int start, pos;
6 pos = start = s.find(' ');
7 int value = stoi(s.substr(0, pos));
8 while (pos != string::npos) {
9 um[s.substr(pos + 1)] += value;
10 pos = s.find('.', pos + 1);
11 }
12 }
13 vector<string> res;
14 res.reserve(um.size());
15 for (const auto &[s, n] : um)
16 res.push_back(to_string(n) + " " + s);
17 return res;
18 }
19 };