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.
public class Solution { public boolean isInterleave(String s1, String s2, String s3) { if (s1.length()+s2.length() != s3.length()) { return false; } boolean[][] res = new boolean[s1.length()+1][s2.length()+1]; res[0][0] = true; for (int i = 1; i <= s1.length() && s1.charAt(i-1) == s3.charAt(i-1); i++) { res[i][0] = true; } for (int i = 1; i <= s2.length() && s2.charAt(i-1) == s3.charAt(i-1); i++) { res[0][i] = true; } for (int i = 1; i <= s1.length(); i++) { for (int j = 1; j <= s2.length(); j++) { char charAt = s3.charAt(i+j-1); if (s1.charAt(i-1)==charAt && res[i-1][j]) { res[i][j] = true; } if (s2.charAt(j-1)==charAt && res[i][j-1]) { res[i][j] = true; } } } return res[s1.length()][s2.length()]; } }
相关推荐
python python_leetcode题解之097_Interleaving_String
js js_leetcode题解之97-interleaving-string.js
c语言基础 c语言_leetcode题解之0097_interleaving_string.zip
leetcode 分类 ...Interleaving String Triangle Distinct Subsequences Decode Ways Palindrome Partitioning II Maximal Rectangle ###Recursion N-Queens N-Queens II Balanced Binary Tree Binar
97.Interleaving String, 115.Distinct Subsequences 2017/04/24 (Lintcode)92.Backpack, (Lintcode)125.Backpack II, (Lintcode)564.Backpack VI 不适用 53.Maximum Subarray, 91.Decode Ways, 96.Unique Binary ...
leetcode卡 OJ 题目汇总 记录下自己做过的oj题目, 也记录下自己对算法以及编程的理解与偏见. 杂感 算法到底是有用还是没用? 这个问题一直萦绕在我的心里. ...String动态规划解决, Recovering BST失败
"interleaving_string.erl","search_insert_position.erl", "three_sum.erl","trapping_rain_water.erl", "valid_palindrome.erl" 个人认为dungeon_game这个题目解题逻辑很体现erlang的函数式的思维逻辑
在编程领域,交错或交织(Interleaving)是一种字符串组合方式,它涉及到将两个或多个字符串的字符交替地组合在一起,形成新的字符串。这个过程在算法设计中有时会被用来处理字符串相关的问题,例如构建字符串的解析...
Processing (interleaving) record buffer is done in the background to not block the main thread and the UI. Also WAV conversion for export is also quite heavy for longer recordings, so best left to ...