Find Duplicate File in System LeetCode solution in JavaScript

1
class Solution {
2
public:
3
vector<vector<string>> findDuplicate(vector<string>& paths) {
4
vector<vector<string>> vec1;
5
for(int i = 0; i < paths.size(); ++i){
6
vector<string> level;
7
string temp1 = paths[i];
8
string temp2 = "";
9
for(int j = 0; j < temp1.length(); ++j){
10
if(temp1[j] == ' '){
11
level.push_back(temp2);
12
temp2 = "";
13
}
14
else
15
temp2 += temp1[j];
16
if(j == temp1.length() - 1)
17
level.push_back(temp2);
18
}
19
vec1.push_back(level);
20
}
21
unordered_map<string, vector<string>> ump;
22
for(int i = 0; i < vec1.size(); ++i){
23
string rootDir = vec1[i][0];
24
for(int j = 1; j < vec1[i].size(); ++j){
25
string str1 = rootDir, str2 = "";
26
int pos = -1;
27
for(int k = 0; k < vec1[i][j].length(); ++k){
28
if(vec1[i][j][k] == '('){
29
pos = k;
30
break;
31
}
32
}
33
str1 += '/';
34
for(int k = 0; k < pos; ++k)
35
str1 += vec1[i][j][k];
36
str2 = vec1[i][j].substr(pos);
37
ump[str2].push_back(str1);
38
}
39
}
40
vector<vector<string>> res;
41
for(auto it = ump.begin(); it != ump.end(); ++it)
42
if(it->second.size() > 1)
43
res.push_back(it->second);
44
return res;
45
}
46
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0