[LeetCode]Interleaving String
来源:互联网 发布:资海网络集团员工待遇 编辑:程序博客网 时间:2024/05/22 14:51
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.
二维动态规划 参考LeetCode题解 戴方勤
public class Solution { public boolean isInterleave(String s1, String s2, String s3) { if(s1.length()==0&&s2.length()==0&&s3.length()==0) return true; if(s1.length()+s2.length()!=s3.length()) return false; boolean f[][] = new boolean[s1.length()+1][s2.length()+1]; for(int i=0;i<s1.length();i++){ f[i+1][0] = (s1.charAt(i)==s3.charAt(i)); } for(int i=0;i<s2.length();i++){ f[0][i+1] = (s2.charAt(i)==s3.charAt(i)); } for(int i=0;i<s1.length();i++){ for(int j=0;j<s2.length();j++){ f[i+1][j+1] = ((s1.charAt(i)==s3.charAt(i+j+1))&&f[i][j+1])|| ((s2.charAt(j)==s3.charAt(i+j+1))&&f[i+1][j]); } } return f[s1.length()][s2.length()]; }}
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
- c++ 32 继承 4
- Delphi XE7的安卓程序如何调用JAVA的JAR,使用JAVA的类?
- Tachyon学习及源码阅读:简介
- ORA-01591 锁被未决分布式事务处理
- 黑马程序员——java基础——网络编程
- [LeetCode]Interleaving String
- kinetic学习之(三) UART
- mahout中得距离测度
- Python 中的range(),arange()函数
- Pow(x, n)
- SDUTOJ 2482 二叉排序树
- CSS学习笔记三
- 安卓4.0蓝牙开发
- 细探颜色值