Given a string, all its fully arranged results are displayed in an array, requiring no repeated results. For example, if a string is given and all its fully ordered results are displayed in an array, no repeated results are required.
For example:
I have a string named "aabb", which should have 4*3*2*1 = 24 results, but considering that there are no duplicates, 6 results are returned, as shown below:
['Aab', 'abab', 'abba', 'baab', 'baba ', 'bbaa']
Therefore, the key to the problem lies in two aspects:
1. How to perform full sorting
2. How to deduplicate results
For full permutation, recursive or non-recursive methods can be used.
Deduplication can be achieved using a hash.
// Recursively solve the full-permutation function permutations (string) {// hash var hash ={} for storing de-duplicated results; // traverse function // from: character array to be traversed // to: String Array of the record path var traverse = function (from, to) {// if the current depth does not reach the leaf if (. length <string. length) {for (var I = 0; I
The above are JavaScript interesting questions: the content is fully arranged and de-duplicated. For more information, please follow the PHP Chinese Network (www.php1.cn )!