0609.cpp (788B)
1 #pragma GCC optimize("fast") 2 static auto _ = []() { 3 ios_base::sync_with_stdio(false); 4 cin.tie(nullptr); 5 cout.tie(nullptr); 6 return 0; 7 }(); 8 9 class Solution { 10 public: 11 vector<vector<string>> findDuplicate(const vector<string> &paths) { 12 unordered_map<string, vector<string>> um; 13 vector<vector<string>> res; 14 15 string path, file; 16 for (const string &entry : paths) { 17 stringstream ss(entry); 18 ss >> path; 19 path += '/'; 20 while (ss >> file) { 21 int idx = file.find('('); 22 um[file.substr(idx)].push_back(path + file.substr(0, idx)); 23 } 24 } 25 26 for (const auto &[_, v] : um) 27 if (v.size() > 1) res.push_back(v); 28 return res; 29 } 30 };