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)


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