【leetcode】Interleaving String
Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.
For example,
Given:
s1 = "aabcc"
,
s2 = "dbbca"
,
When s3 = "aadbbcbcac"
, return true.
When s3 = "aadbbbaccc"
, return false.
class Solution {
public:
bool isInterleave(string s1, string s2, string s3) { int n1=s1.length();
int n2=s2.length();
int n3=s3.length(); if(n1+n2!=n3)
{
return false;
} vector<vector<bool> > dp(n1+,vector<bool>(n2+,false)); dp[][]=true; for(int i=;i<=n1;i++)
{
dp[i][]=dp[i-][]&&s1[i-]==s3[i-];
} for(int j=;j<=n2;j++)
{
dp[][j]=dp[][j-]&&s2[j-]==s3[j-];
} for(int i=;i<=n1;i++)
{
for(int j=;j<=n2;j++)
{
dp[i][j]=(dp[i-][j]&&s1[i-]==s3[i+j-])||(dp[i][j-]&&s2[j-]==s3[i+j-]);
}
} return dp[n1][n2];
}
};
【leetcode】Interleaving String的更多相关文章
- 【leetcode】 Interleaving String (hard)
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...
- 【LeetCode】字符串 string(共112题)
[3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...
- 【LeetCode】8. String to Integer (atoi) 字符串转换整数
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:字符串转整数,atoi,题解,Leetcode, 力扣,P ...
- 【LeetCode】984. String Without AAA or BBB 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字符串构造 日期 题目地址:https://leet ...
- 【leetcode】Scramble String
Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two no ...
- 【leetcode】 Scramble String (hard)★
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- 【LeetCode】8. String to Integer (atoi) 字符串转整数
题目: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ca ...
- 【leetcode】8. String to Integer (atoi)
题目描述: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input ...
- 【leetcode】443. String Compression
problem 443. String Compression Input ["a","a","b","b"," ...
随机推荐
- 搭建OpenWrt开发环境(包括编译过程)
OpenWrt是一个高度模块化.高度自动化的嵌入式linux发行版,其编译和安装过程比普通的linux发行版而言,要简单太多了.如果您是新手,您那恐惧的心大可放到肚子里,呵呵.对于新手来说最麻烦的恐怕 ...
- zepto源代码解读
/** * Created by nono on 14-11-16. */ /* Zepto v1.1.4 - zepto event ajax form ie - zeptojs.com/licen ...
- Mysql-函数coalesce-查询为空设置默认值
coalesce(字段,默认值) select coalesce(title,'liu') from a
- Maven-改变本地存储仓库位置
修改 maven 仓库存放位置: 找到 maven 下的 conf 下的 settings.xml 配置文件,假设maven安装在D:\Server目录中.那么配置文件应该在 D:\Server\ma ...
- Java基础-继承-子类与父类执行顺序
代码 public class Test { public static void main(String[] args) { new Circle(); } } class Draw { publi ...
- 10 个免费的 jQuery 可视化编辑器插件
富文本编辑器,也就是所见即所得的 HTML 编辑器,是网站一个非常重要的组件,特别是对于一些内容发布网站来说.本文介绍 10 个基于 jQuery 的可视化文本编辑器. MarkitUp markIt ...
- Java编程思想学习(七) 抽象类和接口
1.抽象类和抽象方法 抽象方法:不完整的,仅有声明而没有方法体. abstract void f(); 抽象类:包含抽象方法的类.(若一个类包含一个或多个抽象方法,则该类必须限定为抽象的.) 1.用抽 ...
- BZOJ1588 HNOI2002 营业额统计 [Splay入门题]
[HNOI2002]营业额统计 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 4128 Solved: 1305 Description 营业额统计 ...
- Mybatis的ResultMap的使用
本篇文章通过一个实际工作中遇到的例子开始吧: 工程使用Spring+Mybatis+Mysql开发.具体的业务逻辑很重,对象之间一层一层的嵌套.和数据库表对应的是大量的model类,而和前端交互的是V ...
- MySQL 存储过程传参之in, out, inout 参数用法
存储过程传参:存储过程的括号里,可以声明参数. 语法是 create procedure p([in/out/inout] 参数名 参数类型 ..) in :给参数传入值,定义的参数就得到了值 ou ...