|
| 1 | +<p>Given a list of folders <code>folder</code>, return <em>the folders after removing all <strong>sub-folders</strong> in those folders</em>. You may return the answer in <strong>any order</strong>.</p> |
| 2 | + |
| 3 | +<p>If a <code>folder[i]</code> is located within another <code>folder[j]</code>, it is called a <strong>sub-folder</strong> of it. A sub-folder of <code>folder[j]</code> must start with <code>folder[j]</code>, followed by a <code>"/"</code>. For example, <code>"/a/b"</code> is a sub-folder of <code>"/a"</code>, but <code>"/b"</code> is not a sub-folder of <code>"/a/b/c"</code>.</p> |
| 4 | + |
| 5 | +<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.</p> |
| 6 | + |
| 7 | +<ul> |
| 8 | + <li>For example, <code>"/leetcode"</code> and <code>"/leetcode/problems"</code> are valid paths while an empty string and <code>"/"</code> are not.</li> |
| 9 | +</ul> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | +<p><strong class="example">Example 1:</strong></p> |
| 13 | + |
| 14 | +<pre> |
| 15 | +<strong>Input:</strong> folder = ["/a","/a/b","/c/d","/c/d/e","/c/f"] |
| 16 | +<strong>Output:</strong> ["/a","/c/d","/c/f"] |
| 17 | +<strong>Explanation:</strong> Folders "/a/b" is a subfolder of "/a" and "/c/d/e" is inside of folder "/c/d" in our filesystem. |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p><strong class="example">Example 2:</strong></p> |
| 21 | + |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> folder = ["/a","/a/b/c","/a/b/d"] |
| 24 | +<strong>Output:</strong> ["/a"] |
| 25 | +<strong>Explanation:</strong> Folders "/a/b/c" and "/a/b/d" will be removed because they are subfolders of "/a". |
| 26 | +</pre> |
| 27 | + |
| 28 | +<p><strong class="example">Example 3:</strong></p> |
| 29 | + |
| 30 | +<pre> |
| 31 | +<strong>Input:</strong> folder = ["/a/b/c","/a/b/ca","/a/b/d"] |
| 32 | +<strong>Output:</strong> ["/a/b/c","/a/b/ca","/a/b/d"] |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p> </p> |
| 36 | +<p><strong>Constraints:</strong></p> |
| 37 | + |
| 38 | +<ul> |
| 39 | + <li><code>1 <= folder.length <= 4 * 10<sup>4</sup></code></li> |
| 40 | + <li><code>2 <= folder[i].length <= 100</code></li> |
| 41 | + <li><code>folder[i]</code> contains only lowercase letters and <code>'/'</code>.</li> |
| 42 | + <li><code>folder[i]</code> always starts with the character <code>'/'</code>.</li> |
| 43 | + <li>Each folder name is <strong>unique</strong>.</li> |
| 44 | +</ul> |
0 commit comments