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 ...
随机推荐
- 开源字体包缩减font-spider
最近公司产品用微软雅黑,被告~ 领导要求产品后台系统必须更换字体,美工给了个宋体,个人觉得太丑,就网上搜了些处理方法使用 CSS属性 @font-face 自定义字体, 最后决定用 思源黑体 (思源 ...
- wamp5.2 升级到wamp5.3 (转载)
1. 停止WAMP服务器. 2. 去网站windows.php.net 下载php5.3.5 the VC6 Thread Safe build. 不要下载THE INSTALLER. 3. 在 ...
- 过滤HTML
过滤HTML public static string NoHTML(string html){ string[] strArray2 = new string[] { "font" ...
- SQL70001: This statement is not recognized in this context.
关于错误: SQL70001: This statement is not recognized in this context. 的产生原因以及解决办法. 在SQL Server Databas ...
- Jquery常用功能
jQuery 1.4给开发者带来了很多值得兴奋的新特性,同时使用jQuery的人也越来越多,为了方便大家对jQuery的使用,下面列出了一些jQuery使用技巧.比如有禁止右键点击.隐藏搜索文本框文字 ...
- iOS: 学习笔记, Swift与Objective-C混用简明教程(转载)
Swift与Objective-C混用简明教程 转载自:https://github.com/lifedim/SwiftCasts/tree/master/000_mix_swift_objc 我想很 ...
- 通过阅读ASP.NET MVC5 框架解密 路由的一点心得
路由: 1.在ASP.NET中路由不专属与ASP.NET MVC,因为路由(Route)是在system.web 命名空间下的,所以传统的WebForm也可以使用路由. 2.什么叫做路由 采用某种机制 ...
- UFLDL教程之(一)sparseae_exercise
下面,将UFLDL教程中的sparseae_exercise练习中的各函数及注释列举如下 首先,给出各函数的调用关系 主函数:train.m (1)调用sampleIMAGES函数从已知图像中扣取多个 ...
- Hbase对hive的支持没有hdfs的好的原因 及hbase什么时候使用 及rowkey设计技巧
hive-=mareduce 的 split 在 hbase就是 region了,,,,,,,访问region必须通过hregionserver 会造成regionser负担过大, 另外 reg ...
- spm使用之六安装别人写好的spm文档主题模板
上回说到有个nico-one的文档主题模板, https://github.com/lepture/nico-one 把他可以下载了, 放到 C:\Documents and Settings\Adm ...