All Rearrangements of a String
Problem statement
Given a string s, return every different string that can be made by rearranging all of its letters.
If s has repeated letters, list each resulting string only once. Return the strings sorted in dictionary order.
Function
allPermutations(s: String) → List<String>Examples
Example 1
s = "dog"return = ["dgo","dog","gdo","god","odg","ogd"]Three different letters give 3 x 2 x 1 = 6 orders. Sorted like dictionary words, dgo comes first and ogd last.
Example 2
s = "ebb"return = ["bbe","beb","ebb"]Swapping the two bs gives the same string, so there are only 3 different orders, not 6: bbe, beb, ebb.
Example 3
s = "q"return = ["q"]One letter has one order.
Constraints
1 <= s.length <= 6scontains only lowercase English letters; letters may repeat