Leetcode 97. Interleaving String
来源:互联网 发布:软件测试 数据库 测试 编辑:程序博客网 时间:2024/05/16 09:03
题目来源:leetcode
Given s1, s2, s3, find whether s3 is formed by the interleaving ofs1 and s2.
For example,
Given:
s1 ="aabcc",
s2 ="dbbca",
When s3 ="aadbbcbcac", return true.
When s3 ="aadbbbaccc", return false.
思路:DP http://blog.csdn.net/u011095253/article/details/9248073
class Solution { public boolean isInterleave(String s1, String s2, String s3) { if (s3==null||s1==null||s2==null) return false; if((s1.length()+s2.length())!=s3.length()) return false; boolean dp[][]=new boolean[s1.length()+1][s2.length()+1]; dp[0][0]=true; for (int i=1;i<=s2.length();i++){ if (dp[0][i-1]==true&&s2.charAt(i-1)==s3.charAt(i-1)) dp[0][i]=true; } for (int i=1;i<=s1.length();i++){ if (dp[i-1][0]==true&&s1.charAt(i-1)==s3.charAt(i-1)) dp[i][0]=true; } for (int i=1;i<=s1.length();i++) for (int j=1;j<=s2.length();j++){ if ((dp[i-1][j]==true&&s1.charAt(i-1)==s3.charAt(i+j-1))||(dp[i][j-1]==true&&s2.charAt(j-1)==s3.charAt(i+j-1))) dp[i][j]=true; } return dp[s1.length()][s2.length()]; }}
阅读全文
0 0
- LeetCode 97. Interleaving String
- [LeetCode]97.Interleaving String
- [Leetcode] 97. Interleaving String
- LeetCode --- 97. Interleaving String
- [leetcode] 97.Interleaving String
- [leetcode] 97.Interleaving String
- leetcode 97. Interleaving String
- Leetcode - 97.Interleaving String
- leetcode 97. Interleaving String
- LeetCode 97. Interleaving String
- LeetCode 97. Interleaving String
- Leetcode:97. Interleaving String
- Leetcode 97. Interleaving String
- [leetcode] 97. Interleaving String
- LeetCode-97.Interleaving String
- [LeetCode] 97. Interleaving String
- leetcode 97.Interleaving String
- 97. Interleaving String ,leetcode
- JEESZ分布式框架--技术介绍文档
- Toolbar,ActionBar
- ArrayList和LinkedList的区别
- 关于作者
- group by 和order by的相关知识
- Leetcode 97. Interleaving String
- 通达oa2017破解版|通达oa2017网络智能办公系统
- c指针
- 设计模式-抽象工厂模式
- Retrofit+RecyclerView+SwipeRefreshlayout实现上拉刷新和分页加载
- MySQL的字符集
- SQL数据库管理系统的优化方案(表的主键、外键、索引设计)
- 程序是如何执行的(一)a=a+1
- JavaScript 变量提升