标签:first push 各级 bsp nbsp ++ sub domain color
Map手到擒来,先找访问次数,然后把访问域名拆解成各级域名,再加上访问次数。
class Solution { public: vector<string> subdomainVisits(vector<string>& cpdomains) { map<string,int> m; for(int i=0;i<cpdomains.size();i++) { int index_=cpdomains[i].find(‘ ‘); int count=stoi(cpdomains[i].substr(0,index_)); string key = cpdomains[i].substr(index_+1); m[key]+=count; while( (index_=key.find(‘.‘))!=string::npos) { key=key.substr(index_+1); m[key]+=count; } } vector<string> r; for(auto &i:m) { r.push_back(to_string(i.second) + " " + i.first); } return r; } };
标签:first push 各级 bsp nbsp ++ sub domain color
原文地址:https://www.cnblogs.com/biubiuWham/p/10268399.html