267. Palindrome Permutation II

Medium
Hash Table
String
Backtracking

Description

From doocs/leetcode

Given a string s, return all the palindromic permutations (without duplicates) of it.

You may return the answer in any order. If s has no palindromic permutation, return an empty list.

 

Example 1:

Input: s = "aabb"
Output: ["abba","baab"]

Example 2:

Input: s = "abc"
Output: []

 

Constraints:

    • 1 <= s.length <= 16
    • s consists of only lowercase English letters.

Hints

Hint 1
If a palindromic permutation exists, we just need to generate the first half of the string.
Hint 2
To generate all distinct permutations of a (half of) string, use a similar approach from: <a href="/problems/permutations-ii">Permutations II</a> or <a href="/problems/next-permutation">Next Permutation</a>.

Statistics

Acceptance
42.3%
Submissions
178,176
Accepted
75,323