leetcode@ [97] Interleaving Strings
https://leetcode.com/problems/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) {
if(s1.length() + s2.length() != s3.length()) return false;
if(s1.length() == && s2.length() == && s3.length() == ) return true; vector<vector<bool> > dp(s1.length()+, vector<bool>(s2.length()+, false));
for(int i=;i<=s1.length();++i) {
dp[i][] = (s1.substr(,i) == s3.substr(,i))? true: false;
}
for(int j=;j<=s2.length();++j) {
dp[][j] = (s2.substr(,j) == s3.substr(,j))? true: false;
} for(int i=;i<=s1.length();++i) {
for(int j=;j<=s2.length();++j) {
if(dp[i-][j] && s1[i-] == s3[i+j-]) dp[i][j] = true;
else if(dp[i][j-] && s2[j-] == s3[i+j-]) dp[i][j] = true;
else dp[i][j] = false;
}
} return dp[s1.length()][s2.length()];
}
};
leetcode@ [97] Interleaving Strings的更多相关文章
- [LeetCode] 97. Interleaving String 交织相错的字符串
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1and s2. Example 1: Input: s1 = ...
- leetcode 97 Interleaving String ----- java
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...
- [LeetCode] 97. Interleaving String_ Hard tag: Dynamic Programming
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Example 1: Input: s1 = ...
- [leetcode]97. Interleaving String能否构成交错字符串
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Input: s1 = "aabc ...
- Leetcode#97 Interleaving String
原题地址 转化为二维地图游走问题. 比如s1="abab",s2="aab",s3="aabaabb",则有如下地图,其中"^&q ...
- 【一天一道LeetCode】#97. Interleaving String
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given s ...
- 【LeetCode】97. Interleaving String
Interleaving String Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Fo ...
- [LeetCode] Group Shifted Strings 群组偏移字符串
Given a string, we can "shift" each of its letter to its successive letter, for example: & ...
- LeetCode 205 Isomorphic Strings
Problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if ...
随机推荐
- AndroidManifest.xml文件综合详解(转)
一,重要性AndroidManifest.xml是Android应用程序中最重要的文件之一.它是Android程序的全局配置文件,是每个 android程序中必须的文件.它位于我们开发的应用程序的根目 ...
- DeepFace--Facebook的人脸识别(转)
DeepFace基本框架 人脸识别的基本流程是: detect -> aligh -> represent -> classify 人脸对齐流程 分为如下几步: a. 人脸检测,使用 ...
- Jenkins任务启动的后台进程被自动kill
在Jenkins的使用中,遇到过的一个场景是:在web代码更改之后,能自动的部署到测试服务器,我们写了run.sh脚本来重启服务,在使用Jenkins的任务自动跑这个脚本后发现,服务没有起来.开始以为 ...
- 成功解决Tomcat-JDBC-MySQL乱码
0.MySQL-JDBC驱动文档 官方解释 1.数据库的字符编码和表内字段的编码 在MySQL中数据库的字符编码和表内字段的编码的要指定为utf8(utf8_general_ci) 2.jsp中 pa ...
- Apache Flume 简介
转自:http://blog.163.com/guaiguai_family/blog/static/20078414520138100562883/ Flume 是 Cloudera 公司开源出来的 ...
- Servlet入门案例
开发servlet有三种方法: 1.实现Servlet接口; public interface Servlet { void init(ServletConfig var1) throws Servl ...
- POJ2109——Power of Cryptography
Power of Cryptography DescriptionCurrent work in cryptography involves (among other things) large pr ...
- day 2014-04-13
crystal 10:00:40 米多爸爸 11:51:47 很滋润嘛.一般有送股题材的股票都会在送股消息公告之前炒上一阵子,真到了题材兑现就涨不动了,也有些会在除权后走一波填权行情.现在不是牛市,后 ...
- Windows平台下的session0创建进程的问题与解决办法
很多博客都有记载如何在session0下创建进程的办法,也就是使用CreateProcessAsUser.但是这个要求服务的进程有SE_INCREASE_QUOTA_NAME和SE_ASSIGNPRI ...
- stdio.h及cstdio的区别
2013-07-04 16:45:19 找了很多资料,没有说的很明白的,下面是老外的一篇文章,解释的比较清楚,后面给出翻译. Clarifying stdio.h versus cstdio 转自:h ...