-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindDuplicateFileinSystem.cpp
More file actions
34 lines (32 loc) · 1.02 KB
/
findDuplicateFileinSystem.cpp
File metadata and controls
34 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Source: https://leetcode.com/problems/find-duplicate-file-in-system/
// Author: Miao Zhang
// Date: 2021-02-24
class Solution {
public:
vector<vector<string>> findDuplicate(vector<string>& paths) {
// content --> filepath/filename
unordered_map<string, vector<string>> filemap;
for (auto& path: paths) {
string folder;
int i = 0;
while (path[i] != ' ') folder += path[i++];
while (i < path.length()) {
string filename;
string content;
i++;
while (path[i] != '(') filename += path[i++];
i++;
while (path[i] != ')') content += path[i++];
i++;
filemap[content].push_back(folder + "/" + filename);
}
}
vector<vector<string>> res;
for (auto& f: filemap) {
if (f.second.size() > 1) {
res.push_back(std::move(f.second));
}
}
return res;
}
};