-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathLC0609.cpp
More file actions
executable file
·35 lines (30 loc) · 781 Bytes
/
LC0609.cpp
File metadata and controls
executable file
·35 lines (30 loc) · 781 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
29
30
31
32
33
34
35
/*
Problem Statement: https://leetcode.com/problems/find-duplicate-file-in-system/
Time: O(paths)
Space: O(paths)
Author: Mohammed Shoaib, github.com/Mohammed-Shoaib
*/
class Solution {
public:
vector<vector<string>> findDuplicate(vector<string>& paths) {
vector<vector<string>> dups;
unordered_map<string, vector<string>> mp;
for (string& path: paths) {
string token, root, file_name, content;
istringstream ss(path);
ss >> root;
root += '/';
while (ss >> token) {
int pos = token.find('(');
file_name = root + token.substr(0, pos);
content = token.substr(pos + 1);
content.pop_back();
mp[content].push_back(file_name);
}
}
for (auto& [k, v]: mp)
if (v.size() > 1)
dups.push_back(move(v));
return dups;
}
};