-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindDuplicate.cpp
More file actions
28 lines (28 loc) · 887 Bytes
/
findDuplicate.cpp
File metadata and controls
28 lines (28 loc) · 887 Bytes
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
class Solution {
public:
vector<vector<string>> findDuplicate(vector<string>& paths) {
unordered_map<string, vector<string>> mp;
for (auto &p: paths) {
stringstream s(p);
string path, file;
s >> path;
while (s >> file) {
auto pos = file.find("(");
string temp = "";
temp.reserve(path.size() + file.size());
temp.append(path);
temp.append("/");
temp.append(file.substr(0, pos));
string content = file.substr(pos + 1);
mp[content].push_back(std::move(temp));
}
}
vector<vector<string>> ans;
for (auto &it: mp) {
if (it.second.size() > 1) {
ans.push_back(std::move(it.second));
}
}
return ans;
}
};