97.Interleaving-String
97. Interleaving String
题目地址
https://www.jiuzhang.com/solutions/palindrome-partitioning-ii/
题目描述
Given three strings: s1, s2, s3, determine whether s3 is formed by the interleaving of s1 and s2.思路
state: f[i][j] 表示s1的前i个字符和s2的前j个字符能否交替组成s3的前i+j个字符
function: f[i][j] =
f[i - 1][j] && (s1[i - 1] == s3[i + j - 1])
f[i][j - 1] && (s2[j - 1] == s3[i + j - 1])
initialize:
f[i][0] = (s1[0..i - 1] == s3[0..i - 1])
f[0][j] = (s2[0..j - 1] == s3[o..j - 1])代码
Approach #1 Dynamic Programming
Last updated
Was this helpful?