原题链接在这里:
题目:
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 []
.
题解:
与相似.
先判断是否palindrome, 若不是返回空的res. 若是,先判断是否有一个奇数位,若有,改char放中间. 然后两边分别加.
Time Complexity: O(2^n). Space: O(n)层stack.
AC Java:
1 public class Solution { 2 public ListgeneratePalindromes(String s) { 3 List res = new ArrayList (); 4 int [] map = new int[256]; 5 for(int i = 0; i res){29 if(cur.length() == len){30 res.add(new String(cur));31 return;32 }33 for(int i = 0; i