desc.html 2.2 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
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 41 42 43 44 45 46 47 48 49
<p>你是一位系统管理员,手里有一份文件夹列表 <code>folder</code>,你的任务是要删除该列表中的所有 <strong>子文件夹</strong>,并以 <strong>任意顺序</strong> 返回剩下的文件夹。</p>

<p>我们这样定义「子文件夹」:</p>

<ul>
	<li>如果文件夹&nbsp;<code>folder[i]</code>&nbsp;位于另一个文件夹&nbsp;<code>folder[j]</code>&nbsp;下,那么&nbsp;<code>folder[i]</code>&nbsp;就是&nbsp;<code>folder[j]</code>&nbsp;的子文件夹。</li>
</ul>

<p>文件夹的「路径」是由一个或多个按以下格式串联形成的字符串:</p>

<ul>
	<li><code>/</code>&nbsp;后跟一个或者多个小写英文字母。</li>
</ul>

<p>例如,<code>/leetcode</code>&nbsp;&nbsp;<code>/leetcode/problems</code>&nbsp;都是有效的路径,而空字符串和&nbsp;<code>/</code>&nbsp;不是。</p>

<p>&nbsp;</p>

<p><strong>示例 1:</strong></p>

<pre><strong>输入:</strong>folder = [&quot;/a&quot;,&quot;/a/b&quot;,&quot;/c/d&quot;,&quot;/c/d/e&quot;,&quot;/c/f&quot;]
<strong>输出:</strong>[&quot;/a&quot;,&quot;/c/d&quot;,&quot;/c/f&quot;]
<strong>解释:</strong>&quot;/a/b/&quot;&quot;/a&quot; 的子文件夹,而 &quot;/c/d/e&quot;&quot;/c/d&quot; 的子文件夹。
</pre>

<p><strong>示例 2:</strong></p>

<pre><strong>输入:</strong>folder = [&quot;/a&quot;,&quot;/a/b/c&quot;,&quot;/a/b/d&quot;]
<strong>输出:</strong>[&quot;/a&quot;]
<strong>解释:</strong>文件夹 &quot;/a/b/c&quot;&quot;/a/b/d/&quot; 都会被删除,因为它们都是 &quot;/a&quot; 的子文件夹。
</pre>

<p><strong>示例 3:</strong></p>

<pre><strong>输入:</strong>folder = [&quot;/a/b/c&quot;,&quot;/a/b/d&quot;,&quot;/a/b/ca&quot;]
<strong>输出:</strong>[&quot;/a/b/c&quot;,&quot;/a/b/ca&quot;,&quot;/a/b/d&quot;]
</pre>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
	<li><code>1 &lt;= folder.length&nbsp;&lt;= 4 * 10^4</code></li>
	<li><code>2 &lt;= folder[i].length &lt;= 100</code></li>
	<li><code>folder[i]</code>&nbsp;只包含小写字母和 <code>/</code></li>
	<li><code>folder[i]</code>&nbsp;总是以字符 <code>/</code>&nbsp;起始</li>
	<li>每个文件夹名都是唯一的</li>
</ul>