代码拉取完成,页面将自动刷新
<p>Under the grammar given below, strings can represent a set of lowercase words. Let <code>R(expr)</code> denote the set of words the expression represents.</p>
<p>The grammar can best be understood through simple examples:</p>
<ul>
<li>Single letters represent a singleton set containing that word.
<ul>
<li><code>R("a") = {"a"}</code></li>
<li><code>R("w") = {"w"}</code></li>
</ul>
</li>
<li>When we take a comma-delimited list of two or more expressions, we take the union of possibilities.
<ul>
<li><code>R("{a,b,c}") = {"a","b","c"}</code></li>
<li><code>R("{{a,b},{b,c}}") = {"a","b","c"}</code> (notice the final set only contains each word at most once)</li>
</ul>
</li>
<li>When we concatenate two expressions, we take the set of possible concatenations between two words where the first word comes from the first expression and the second word comes from the second expression.
<ul>
<li><code>R("{a,b}{c,d}") = {"ac","ad","bc","bd"}</code></li>
<li><code>R("a{b,c}{d,e}f{g,h}") = {"abdfg", "abdfh", "abefg", "abefh", "acdfg", "acdfh", "acefg", "acefh"}</code></li>
</ul>
</li>
</ul>
<p>Formally, the three rules for our grammar:</p>
<ul>
<li>For every lowercase letter <code>x</code>, we have <code>R(x) = {x}</code>.</li>
<li>For expressions <code>e<sub>1</sub>, e<sub>2</sub>, ... , e<sub>k</sub></code> with <code>k >= 2</code>, we have <code>R({e<sub>1</sub>, e<sub>2</sub>, ...}) = R(e<sub>1</sub>) ∪ R(e<sub>2</sub>) ∪ ...</code></li>
<li>For expressions <code>e<sub>1</sub></code> and <code>e<sub>2</sub></code>, we have <code>R(e<sub>1</sub> + e<sub>2</sub>) = {a + b for (a, b) in R(e<sub>1</sub>) × R(e<sub>2</sub>)}</code>, where <code>+</code> denotes concatenation, and <code>×</code> denotes the cartesian product.</li>
</ul>
<p>Given an expression representing a set of words under the given grammar, return <em>the sorted list of words that the expression represents</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> expression = "{a,b}{c,{d,e}}"
<strong>Output:</strong> ["ac","ad","ae","bc","bd","be"]
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> expression = "{{a,z},a{b,c},{ab,z}}"
<strong>Output:</strong> ["a","ab","ac","z"]
<strong>Explanation:</strong> Each distinct word is written only once in the final answer.
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= expression.length <= 60</code></li>
<li><code>expression[i]</code> consists of <code>'{'</code>, <code>'}'</code>, <code>','</code>or lowercase English letters.</li>
<li>The given <code>expression</code> represents a set of words based on the grammar given in the description.</li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。