Skip to content

Latest commit

 

History

History
27 lines (24 loc) · 810 Bytes

609. Find Duplicate File in System.md

File metadata and controls

27 lines (24 loc) · 810 Bytes
class Solution {
public:
    vector<vector<string>> findDuplicate(vector<string>& paths) {
        unordered_map<string, vector<string>> files;
        vector<vector<string>> res;
        
        for (auto& path : paths) {
            stringstream ss(path);
            string dir;
            string file;
            getline(ss, dir, ' ');
            while (getline(ss, file, ' ')) {
                string file_name = dir + '/' + file.substr(0, file.find('('));
                string content = file.substr(file.find('(') + 1, file.find(')') - file.find('(') - 1);
                files[content].push_back(file_name);
            }
        }
        
        for (auto file : files)
            if (file.second.size() > 1)
                res.push_back(file.second);
        return res;
    }
};