All Permutations of Subsets with duplication

  1. Links

  1. 题目

  2. Given a string with no duplicate characters, return a list with all permutations of the string and all its subsets.

    Examples

    Set = “abc”, all permutations are [“”, “a”, “ab”, “abc”, “ac”, “acb”, “b”, “ba”, “bac”, “bc”, “bca”, “c”, “cb”, “cba”, “ca”, “cab”].

    Set = “”, all permutations are [“”].

    Set = null, all permutations are [].

  3. 思想

    1. DFS

    2. 在原来的 all subset II without duplication 的基础里面,在不选当前的char, action[pos] 时把所有的相同的char都不考虑进去

    3. example

      1. action = [a b e e e c d]

      2. 如果我考虑第一个e,那么就考虑 剩下的e并且每个e都只考虑一次,那么就会有 “e...”, "ee...", "eee..." 这3中情况并且1个e, 2个e, 3个e的情况都是只出现一次

      3. 如果我不考虑第一个e,那么就不考虑剩下的所有e了。因为如果在不选第一个e的情况下考虑其他e,就会出现“ee..”, "eee.."的情况和 case2 重复 所以代码变成

  4. Coding

Last updated

Was this helpful?