-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1233.cpp
37 lines (33 loc) · 840 Bytes
/
1233.cpp
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
#include "leetcode.hpp"
class Solution {
public:
vector<string> removeSubfolders(vector<string>& folder) {
vector<string> ret;
sort(folder.begin(), folder.end());
ret.push_back(folder.front());
string last = ret.back();
for (auto i = 1; i < folder.size(); ++i) {
if (folder[i].substr(0, last.size()) == last &&
folder[i][last.size()] == '/') {
continue;
} else {
ret.push_back(folder[i]);
last = ret.back();
}
}
return ret;
}
};
int main(int argc, char const* argv[]) {
Solution s;
vector<vector<string>> t = {
{"/a", "/a/b", "/c/d", "/c/d/e", "/c/f"},
{"/a", "/a/b/c", "/a/b/d"},
{"/a/b/c", "/a/b/ca", "/a/b/d"},
{"/ah/al/am", "/ah/al"},
};
for (auto tc : t) {
auto ret = s.removeSubfolders(tc);
}
return 0;
}