加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

[Swift]LeetCode1087. 字母切换 | Permutation of Letters

发布时间:2020-12-14 04:34:45 所属栏目:百科 来源:网络整理
导读:★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ?微信公众号:山青咏芝(shanqingyongzhi) ?博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/) ?GitHub地址:https://github.com/strengthen/LeetCode ?原

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
?微信公众号:山青咏芝(shanqingyongzhi)
?博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
?GitHub地址:https://github.com/strengthen/LeetCode
?原文地址:https://www.cnblogs.com/strengthen/p/11031602.html?
?如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
?原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

A string?S?represents a list of words.

Each letter in the word has 1 or more options.? If there is one option,the letter is represented as is.? If there is more than one option,then curly braces delimit the options.? For example,?"{a,b,c}"?represents options?["a","b","c"].

For example,c}d{e,f}"?represents the list?["ade","adf","bde","bdf","cde","cdf"].

Return all words that can be formed in this manner,in lexicographical order.?

Example 1:

Input: "{a,b}c{d,e}f"
Output: ["acdf","acef","bcdf","bcef"] 

Example 2:

Input: "abcd"
Output: ["abcd"]?

Note:

  1. 1 <= S.length <= 50
  2. There are no?nested curly brackets.
  3. All characters inside a pair of?consecutive opening and ending curly brackets are different.

我们用一个特殊的字符串?S?来表示一份单词列表,之所以能展开成为一个列表,是因为这个字符串?S?中存在一个叫做「选项」的概念:

单词中的每个字母可能只有一个选项或存在多个备选项。如果只有一个选项,那么该字母按原样表示。

如果存在多个选项,就会以花括号包裹来表示这些选项(使它们与其他字母分隔开),例如?"{a,c}"?表示?["a","c"]

例子:"{a,f}"?可以表示单词列表?["ade","cdf"]

请你按字典顺序,返回所有以这种方式形成的单词。?

示例 1:

输入:"{a,e}f"
输出:["acdf","bcef"]

示例 2:

输入:"abcd"
输出:["abcd"]?

提示:

  1. 1 <= S.length <= 50
  2. 你可以假设题目中不存在嵌套的花括号
  3. 在一对连续的花括号(开花括号与闭花括号)之间的所有字母都不会相同

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读