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 ...
随机推荐
- leetcode6 Reverse Words in a String 单词取反
Reverse Words in a String 单词取反 whowhoha@outlook.com Question: Given an input string s, reverse the ...
- 站长、运维必备| 网站可用性监控产品 OneAPM Cloud Test 上线
白天太忙,到了晚上才发现网站一天都没有访问量? 直到有用户投诉才发现网站完全无法访问? 还要每月付费才能及时了解网站可用情况? 监控频率太低,不能及时发现网站不可用? 第三方服务宕机,导致您的网站不可 ...
- Topo图
http://blog.csdn.net/youfangyuan/article/details/8367398 http://joshuaxiao.iteye.com/blog/2224120 ht ...
- MVC 文件上传和图片剪辑
http://www.cnblogs.com/hinton/archive/2012/03/01/2375465.html http://gallery.kissyui.com/uploader/1. ...
- 新建并保存一个空的Excel
测试用的 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; ...
- 函数buf_LRU_search_and_free_block
/******************************************************************//** Try to free a replaceable bl ...
- WP8触摸感应Manipulation的操作
触控感应不同事件的处理: 可将以下三个事件,绑定到一个控件中. /// <summary> /// 触摸开始事件 /// </summary> /// <param na ...
- js实现对数据库的增删查改
1.查询 复制代码 代码如下: <HTML> <HEAD> <TITLE>数据查询</TITLE> <Script > var conn = ...
- BZOJ_1027_[JSOI2007]_合金_(计算几何+Floyd求最小环)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1027 共三种金属,\(m\)种材料,给出每种材料中三种金属的占比. 给出\(n\)种合金的三种 ...
- BZOJ2150: 部落战争
题解: 把每个点拆成入点和出点,因为必须经过一次且只能经过一次.所以在两个点之间连一条上界=下界=1的边. 然后再s到每个入点连边,每个出点向t连边,点与点之间... 求最小流就可以过了... (感觉 ...