博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode Palindrome Permutation II
阅读量:4355 次
发布时间:2019-06-07

本文共 840 字,大约阅读时间需要 2 分钟。

原题链接在这里:

题目:

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 List
generatePalindromes(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

 

转载于:https://www.cnblogs.com/Dylan-Java-NYC/p/5265380.html

你可能感兴趣的文章
全景图制作详解
查看>>
React之todo-list
查看>>
cocoapods降级版本
查看>>
MYSQL复习笔记4-基本SQL语句
查看>>
C#&java重学笔记(函数)
查看>>
14软件G2班
查看>>
bzoj 1977 [BeiJing2010组队]次小生成树 Tree
查看>>
bzoj 2119 股市的预测——枚举长度的关键点+后缀数组
查看>>
maven:新建的maven工程需要添加一下插件
查看>>
改变和恢复view的方向
查看>>
C#调用金数据API
查看>>
Convert Sorted List to Binary Search Tree
查看>>
Leetcode:Unique Binary Search Trees
查看>>
D3.js 绘制散点图
查看>>
HTML—链接
查看>>
将进程设置为守护进程
查看>>
用连接池提高Servlet访问数据库的效率
查看>>
luogu P1494 [国家集训队]小Z的袜子 ( 普 通 )
查看>>
树的数据结构
查看>>
MyEclipse导入Color Theme
查看>>