LeetCode - Interleaving String
来源:互联网 发布:unity3d 中国象棋 编辑:程序博客网 时间:2024/05/01 19:04
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 len1=s1.size(),len2=s2.size(),len3=s3.size();if(len1+len2!=len3){return false;}vector<vector<bool> > matrix(len1+1,vector<bool>(len2+1,false));matrix[len1][len2]=true;for(int i=len1-1;i>=0;i--){matrix[i][len2]=s1[i]==s3[i+len2]&&matrix[i+1][len2];}for(int i=len2-1;i>=0;i--){matrix[len1][i]=s2[i]==s3[i+len1]&&matrix[len1][i+1];} for(int i=len1-1;i>=0;i--){for(int j=len2-1;j>=0;j--){matrix[i][j]=(matrix[i+1][j]&&s1[i]==s3[i+j])||(matrix[i][j+1]&&s2[j]==s3[i+j]);}}return matrix[0][0]; }};
- LeetCode: Interleaving String
- LeetCode Interleaving String
- LeetCode: Interleaving String
- [Leetcode] Interleaving String
- [LeetCode] Interleaving String
- leetcode 68: Interleaving String
- [Leetcode] Interleaving String
- LeetCode - Interleaving String
- [LeetCode]Interleaving String
- LeetCode: Interleaving String
- Leetcode: Interleaving String
- [Leetcode]Interleaving String
- Leetcode: Interleaving String
- LeetCode:Interleaving String
- LeetCode-Interleaving String
- [leetcode] Interleaving String@DP
- LeetCode:Interleaving String
- LeetCode - Interleaving String
- 企业建站的几点小忌讳
- ExecutorService线程池
- 分析google开源框架zxing
- 开发一款找手机的软件,通过电脑来操作
- linux 命令行一些要点(二)
- LeetCode - Interleaving String
- Kendo UI开发教程(15): Kendo MVVM 数据绑定(四) Disabled/Enabled
- MySQL主流存储引擎概述
- 批处理代码遇到路径中间有空格怎么办?
- JAVA -NIO实现(一)
- 内核初始化优化宏(__init, __devinit)
- .NET中实现Word,Excle文档到PDF文档的转化
- jdbc详解(二)
- ios学习笔记:UIAlertView的使用