https://leetcode.com/problems/find-duplicate-file-in-system/description/
vector<vector<string>> findDuplicate(vector<string>& paths) {
unordered_map<string,vector<string>> con2path;
for(string pth : paths) {
stringstream ss(pth);
string item;
getline(ss, item, ' ');
string path = item + "/";
while(getline(ss, item, ' ')) {
//size_t l = item.find('(');
//size_t r = item.find(')');
//string fname = path + item.substr(0, l);
//string content = item.substr(l+1, r-l);
stringstream ssi(item);
string fname;
getline(ssi, fname, '(');
fname = path + fname;
string content;
getline(ssi, content, ')');
con2path[content].push_back(fname);
}
}
vector<vector<string>> res;
for(auto &x : con2path) if(x.second.size()>1) res.push_back(x.second);
return res;
}
No comments:
Post a Comment