diff options
Diffstat (limited to 'misc.cpp')
-rw-r--r-- | misc.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/misc.cpp b/misc.cpp new file mode 100644 index 0000000..8263244 --- /dev/null +++ b/misc.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + vector<string> removeSubfolders(vector<string> &folder) { + sort(folder.begin(), folder.end()); + vector<string> res; + + for (auto s : folder) { + if (res.size() == 0) { + res.push_back(s); + continue; + } + + string parent = res[res.size() - 1]; + if (s.substr(0, parent.size() + 1) != parent + '/') + res.push_back(s); + } + + return res; + } +}; |