[Swift]LeetCode1233. 刪除子文件夾 | Remove Sub-Folders from the Filesystem

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:爲敢(WeiGanTechnologies)
➤我的域名:https://www.zengqiang.org
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-ogsyoqxm-bz.html
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html

Given a list of folders, remove all sub-folders in those folders and return in any order the folders after removing.git

If a folder[i] is located within another folder[j], it is called a sub-folder of it.github

The format of a path is one or more concatenated strings of the form: / followed by one or more lowercase English letters. For example, /leetcode and /leetcode/problems are valid paths while an empty string and / are not.微信

Example 1:ide

Input: folder = ["/a","/a/b","/c/d","/c/d/e","/c/f"]
Output: ["/a","/c/d","/c/f"]
Explanation: Folders "/a/b/" is a subfolder of "/a" and "/c/d/e" is inside of folder "/c/d" in our filesystem.
Example 2:code

Input: folder = ["/a","/a/b/c","/a/b/d"]
Output: ["/a"]
Explanation: Folders "/a/b/c" and "/a/b/d/" will be removed because they are subfolders of "/a".
Example 3:orm

Input: folder = ["/a/b/c","/a/b/ca","/a/b/d"]
Output: ["/a/b/c","/a/b/ca","/a/b/d"]htm

Constraints:blog

1 <= folder.length <= 4 * 10^4
2 <= folder[i].length <= 100
folder[i] contains only lowercase letters and '/'
folder[i] always starts with character '/'
Each folder name is unique.leetcode


你是一位系統管理員,手裏有一份文件夾列表 folder,你的任務是要刪除該列表中的全部 子文件夾,並以 任意順序 返回剩下的文件夾。

咱們這樣定義「子文件夾」:

若是文件夾 folder[i] 位於另外一個文件夾 folder[j] 下,那麼 folder[i] 就是 folder[j] 的子文件夾。
文件夾的「路徑」是由一個或多個按如下格式串聯造成的字符串:

/ 後跟一個或者多個小寫英文字母。
例如,/leetcode 和 /leetcode/problems 都是有效的路徑,而空字符串和 / 不是。

示例 1:

輸入:folder = ["/a","/a/b","/c/d","/c/d/e","/c/f"]
輸出:["/a","/c/d","/c/f"]
解釋:"/a/b/" 是 "/a" 的子文件夾,而 "/c/d/e" 是 "/c/d" 的子文件夾。
示例 2:

輸入:folder = ["/a","/a/b/c","/a/b/d"]
輸出:["/a"]
解釋:文件夾 "/a/b/c" 和 "/a/b/d/" 都會被刪除,由於它們都是 "/a" 的子文件夾。
示例 3:

輸入:folder = ["/a/b/c","/a/b/d","/a/b/ca"]
輸出:["/a/b/c","/a/b/ca","/a/b/d"]

提示:

1 <= folder.length <= 4 * 10^42 <= folder[i].length <= 100folder[i] 只包含小寫字母和 /folder[i] 老是以字符 / 起始每一個文件夾名都是惟一的

相關文章
相關標籤/搜索