aboutsummaryrefslogtreecommitdiff
path: root/misc.cpp
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-10-24 21:55:18 -0600
committerJack Sangdahl <[email protected]>2024-10-24 21:55:18 -0600
commit54e0305c7a0927ea74163843e547dcb93d84344c (patch)
tree7c2990bf39895c1254d1cda6c67318f16df54f4b /misc.cpp
parent0297643f9bc94881eb3ea3b3f91741fcf34a4d7d (diff)
downloadleetcode-54e0305c7a0927ea74163843e547dcb93d84344c.tar.gz
leetcode-54e0305c7a0927ea74163843e547dcb93d84344c.zip
1233. remove sub-folders from the filesystem
Diffstat (limited to 'misc.cpp')
-rw-r--r--misc.cpp20
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;
+ }
+};