LeetCode Interleaving String
来源:互联网 发布:南宁脱贫攻坚大数据app 编辑:程序博客网 时间:2024/05/01 12:05
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) { // Start typing your C/C++ solution below // DO NOT write int main() function if(s1.size()+s2.size()!=s3.size()) return false; vector<vector<int> > result; result.resize(s1.size()+1); for(int i=0;i<result.size();++i){ result[i].resize(s2.size()+1); } result[0][0]=true; for(int i=0;i<s1.size();++i){ result[i+1][0]=result[i][0]&&(s1[i]==s3[i]); } for(int i=0;i<s2.size();++i){ result[0][i+1]=result[0][i]&&(s2[i]==s3[i]); } for(int i=0;i<s1.size();++i){ for(int j=0;j<s2.size();++j){ result[i+1][j+1]=(result[i][j+1]&&s1[i]==s3[i+j+1])|| (result[i+1][j]&&s2[j]==s3[i+j+1]); } } return result[s1.size()][s2.size()]; }};
- 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
- xml学习笔记(5)sax解析
- SharePoint 2010 with Reporting Services 2008 dealing with oracle data
- zoj1005-Jugs
- 调试调试,不如自己琢磨
- fortran中windows与lunix中结果不一样
- LeetCode Interleaving String
- python技巧
- 图像处理之滤波器
- Hadoop, HBase, Zookeepr insanity
- 【PHP图片处理】PHPThumb、EasyPhpThumbnail
- 使用crs_profile管理RAC资源配置文件
- python读取excel表格统计不同网段IP个数
- HDU 1299 素数筛选+求因子个数
- Linux IO协议栈框图