leetcode

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

0609.cpp (788B)


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