leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1233.cpp (442B)
0 class Solution {
1 public:
2 vector<string> removeSubfolders(vector<string> &folder) {
3 sort(folder.begin(), folder.end());
4 vector<string> res = {folder[0]};
6 for (int i = 1; i < folder.size(); i++) {
7 const string root = res.back() + "/";
8 const string prefix = folder[i].substr(0, root.size());
9 if (prefix != root) res.push_back(folder[i]);
10 }
12 return res;
13 }
14 };