-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path609_findDupFileInSystem.cpp
More file actions
53 lines (49 loc) · 1.37 KB
/
Copy path609_findDupFileInSystem.cpp
File metadata and controls
53 lines (49 loc) · 1.37 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;
class Solution {
public:
vector<vector<string> > findDuplicate(vector<string>& paths) {
map<string, vector<string> > mapping;
for (size_t i=0; i<paths.size(); ++i)
{
istringstream sin(paths[i]);
string dir, file;
sin >> dir;
while (sin >> file)
{
size_t pos = file.find('(');
string filename = file.substr(0, pos);
string content = file.substr(pos+1, file.length()-pos-2);
filename = dir + "/" + filename;
if ( mapping.find(content) == mapping.end() )
{
vector<string> files;
files.push_back(filename);
mapping[content] = files;
} else
{
mapping[content].push_back(filename);
}
}
}
vector<vector<string> > res;
typedef map<string, vector<string> >::iterator SVIT;
for (SVIT it = mapping.begin(); it != mapping.end(); ++it)
{
if (it->second.size() > 1)
{
res.push_back(it->second);
}
}
return res;
}
};
int main()
{
Solution solution;
return 0;
}