Find Duplicate File in System LeetCode solution in C++

1
class Solution {
2
public:
3
vector<vector<string>> findDuplicate(vector<string> &paths) {
4
vector<vector<string>> ans;
5
unordered_map<string, vector<string>> map;
6
for (auto &s : paths) {
7
string startPath;
8
bool firstSpace = true;
9
for (int i = 0; i < s.size(); i++) {
10
if (firstSpace) {
11
startPath += s[i];
12
}
13

14
if (firstSpace && s[i] == ' ') {
15
firstSpace = false;
16
startPath.pop_back();
17
}
18

19
if (s[i] == ' ') {
20
i++;
21
string fileName;
22

23
while (s[i] != '(') {
24
fileName += s[i++];
25
}
26

27
i++;
28
string fileContent;
29

30
while (s[i] != ')') {
31
fileContent += s[i++];
32
}
33

34
map[fileContent].push_back(startPath + '/' + fileName);
35
}
36
}
37
}
38
for (auto &i : map) {
39
if (i.second.size() > 1) {
40
ans.push_back(i.second);
41
}
42
}
43
return ans;
44
};
45
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0