We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f4027ae commit e671351Copy full SHA for e671351
Interleaving String/Solution.py
@@ -0,0 +1,21 @@
1
+class Solution:
2
+ def isInterleave(self, s1: str, s2: str, s3: str) -> bool:
3
+ if len(s1) + len(s2) != len(s3):
4
+ return False
5
+
6
+ m = len(s1)
7
+ n = len(s2)
8
9
+ dp = [[False] * (n+1) for _ in range(m+1)]
10
11
+ dp[0][0] = True
12
+ for i in range(1, m+1):
13
+ dp[i][0] = dp[i-1][0] and s3[i-1] == s1[i-1]
14
+ for j in range(1, n+1):
15
+ dp[0][j] = dp[0][j-1] and s3[j-1] == s2[j-1]
16
17
18
19
+ dp[i][j] = (dp[i-1][j] and s3[i+j-1]==s1[i-1]) or (dp[i][j-1] and s3[i+j-1]==s2[j-1])
20
21
+ return dp[-1][-1]
0 commit comments