This one is from leetcode. Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form.
For example:
Given s = “aabb”, return [“abba”, “baab”].
Given s = “abc”, return [].
Solution. We should get string where each unique char is only half number of original string. We permutate it. Then we add the result with the reverse part. For example, for “aabb”, we should get all permutation of “ab”, which are “ab” and “ba”. Then we add the reverse part, and we have “abba”, “baab”.
Besides, another case is when there is an odd char. We should put it in the middle position.
Check my code on github: link