Permutations II
Problem statement
Given a lowercase string s, return every distinct permutation of its characters exactly once.
Return the permutations in ascending lexicographic order. Equal characters from different input positions must not create duplicate strings.
Function
uniquePermutations(s: String) → String[]Examples
Example 1
s = "aab"return = ["aab","aba","baa"]There are three distinct arrangements after duplicate swaps of the two a characters are removed.
Example 2
s = "xxyy"return = ["xxyy","xyxy","xyyx","yxxy","yxyx","yyxx"]The four positions have six unique arrangements because each character appears twice.
Example 3
s = "z"return = ["z"]A one-character string has one permutation.
Constraints
1 <= s.length <= 8.scontains only lowercase English letters.