leetcode 字符串分割对称
public class Solution {
public List<List<String>> partition(String s) {
int len=s.length();
boolean dp[][]=new boolean[len][len];
get(dp,s);
ArrayList<ArrayList<String>> res=new ArrayList<ArrayList<String>>();
ArrayList<String> temp=new ArrayList<String>();
dfs(res,temp,0,dp,s);
return (List)res; }
public void get(boolean dp[][],String s)
{
char c[]=s.toCharArray();
int len=s.length();
//single character is duichen
for(int i=0;i<len-1;i++)
{
dp[i][i]=true;
if(c[i]==c[i+1]) dp[i][i+1]=true; }
dp[len-1][len-1]=true; for(int l=2;l<len;l++)
{
for(int k=0;k<len-l;k++)
{
dp[k][k+l]=dp[k+1][k+l-1]&&(c[k]==c[k+l]);
} } }
public void dfs(ArrayList<ArrayList<String>> res,ArrayList<String> temp,int l,boolean dp[][],String s)
{
if(l==dp.length)
{
res.add(new ArrayList(temp));
}
else
{
for(int j=0;j<dp.length;j++)
{
if(dp[l][j])
{
ArrayList<String> t=new ArrayList<String>(temp);
t.add(s.substring(l,j+1));
dfs(res,t,j+1,dp,s); } } }
} }
leetcode 字符串分割对称的更多相关文章
- LeetCode Isomorphic Strings 对称字符串
题意:如果两个字符串是对称的,就返回true.对称就是将串1中的同一字符都一起换掉,可以换成同串2一样的. 思路:ASCII码表哈希就行了.需要扫3次字符串,共3*n的计算量.复杂度O(n).从串左开 ...
- OC3_字符串分割
// // main.m // OC3_字符串分割 // // Created by zhangxueming on 15/6/11. // Copyright (c) 2015年 zhangxuem ...
- SQL Server 游标运用:鼠标轨迹字符串分割
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 游标模板(Cursor Template) 鼠标轨迹字符串分割SQL脚本实现(SQL Code ...
- Oracle 超长字符串分割劈分
Oracle 超长字符串分割劈分,具体能有多长没测过,反正很大.... 下面,,,,直奔主题了: CREATE OR REPLACE FUNCTION splitstr(p_string IN clo ...
- php学习零散笔记—字符串分割、fetch函数和单双引号。
1 字符串分割——split()函数和preg_split()函数 split — 用正则表达式将字符串分割到数组中——貌似PHP5.3以上已不赞成使用 array split ( string $p ...
- 工作中用到的oracle字符串分割整理
oracle部分: 定义类型(用于字符串分割): create or replace TYPE "STR_SPLIT" IS TABLE OF VARCHAR2 (4000); 字 ...
- Python 字符串分割的方法
在平时工作的时候,发现对于字符串分割的方法用的比较多,下面对分割字符串方法进行总结一下:第一种:split()函数split()函数应该说是分割字符串使用最多的函数用法:str.split('分割符' ...
- 在C++中实现字符串分割--split
字符串分割 在一些比较流行的语言中,字符串分割是一个比较重要的方法,不论是在python,java这样的系统级语言还是js这样的前端脚本都会在用到字符串的分割,然而在c++中却没有这样的方法用来调用. ...
- 随笔 JS 字符串 分割成字符串数组 并动态添加到指定ID的DOM 里
JS /* * 字符串 分割成字符串数组 并动态添加到指定ID的DOM 里 * @id 要插入到DOM元素的ID * * 输入值为图片URL 字符串 * */ function addImages(i ...
随机推荐
- Eclipse快捷键,前几个很实用
F3 :查看实现 F4(或control + T) :继承树 control + F6 :切换文件 control + F7 :切换视图 control + F8 :切换模板 control + O ...
- Objective-C发展历史
Objective-C发展历史 苹果图标由来: 被咬了一口苹果的LOGO是为了纪念计算机科学的创始人阿兰· 麦席森· 图灵.当年图灵由于身为同性恋者,被强行 "治疗",在被迫注射大 ...
- Function.prototype.apply()
文章地址:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply ...
- Observer 模式
Observer模式要解决的问题为:建立一个一(Subject)对多(Observer)的依赖关系,并且做到当“一”变化的时候,依赖这个“一”的多也能够同步改变.最常见的一个例子就是:对同一组数据进行 ...
- 速卖通api--发起授权
<? $reqURL_onLine = "https://gw.api.alibaba.com/openapi/http/1/system.oauth2/getToken/494739 ...
- hibernate错误提示
2016-05-03 09:45:03,275 -- WARN -- org.hibernate.internal.util.xml.DTDEntityResolver.resolveEntity( ...
- GCC选项-Xlinker和-Wl区别
写下给自己备忘,在一次使用GCC的过程中发现了原来传递给链接器ld可以同时使用Xlinker和Wl两种命令,这两个命令都可以正确传递给ld作为使用,现在总结下两者的区别. Xlinker后面跟的参数第 ...
- Struts2常规配置
默认配置文件名:struts.xml WEB-INF/classes下(放到src下) Struts2的有效常量可以查看 org\apache\struts2 下的 default.p ...
- 安装ImageMagick扩展出现configure: error: not found. Please provide a path to MagickWand-config or Wand- config program
安装ImageMagick扩展报错: checking ImageMagick MagickWand API configuration program... checking Testing /u ...
- 学渣也要搞 laravel(4)—— 服务 加解密篇
使用 Crypt::encrypt() 对数据进行加密,[注意要引入 use Illuminate\Support\Facades\Crypt;; ] 简单的做个测试: 先分配一个路由: Route: ...