-
Notifications
You must be signed in to change notification settings - Fork 160
/
remove-sub-folders-from-the-filesystem.md
40 lines (30 loc) · 1.92 KB
/
remove-sub-folders-from-the-filesystem.md
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
38
39
40
<p>Given a list of folders, remove all sub-folders in those folders and return in <strong>any order</strong> the folders after removing.</p>
<p>If a <code>folder[i]</code> is located within another <code>folder[j]</code>, it is called a sub-folder of it.</p>
<p>The format of a path is one or more concatenated strings of the form: <code>/</code> followed by one or more lowercase English letters. For example, <code>/leetcode</code> and <code>/leetcode/problems</code> are valid paths while an empty string and <code>/</code> are not.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> folder = ["/a","/a/b","/c/d","/c/d/e","/c/f"]
<strong>Output:</strong> ["/a","/c/d","/c/f"]
<strong>Explanation:</strong> Folders "/a/b/" is a subfolder of "/a" and "/c/d/e" is inside of folder "/c/d" in our filesystem.
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> folder = ["/a","/a/b/c","/a/b/d"]
<strong>Output:</strong> ["/a"]
<strong>Explanation:</strong> Folders "/a/b/c" and "/a/b/d/" will be removed because they are subfolders of "/a".
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> folder = ["/a/b/c","/a/b/ca","/a/b/d"]
<strong>Output:</strong> ["/a/b/c","/a/b/ca","/a/b/d"]
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= folder.length <= 4 * 10^4</code></li>
<li><code>2 <= folder[i].length <= 100</code></li>
<li><code>folder[i]</code> contains only lowercase letters and '/'</li>
<li><code>folder[i]</code> always starts with character '/'</li>
<li>Each folder name is unique.</li>
</ul>