Interleaving String LeetCode solution in Python

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
dp = [[False] * (len(s2) + 1) for i in range(len(s1) + 1)]
6
dp[len(s1)][len(s2)] = True
7

8
for i in range(len(s1), -1, -1):
9
for j in range(len(s2), -1, -1):
10
if i < len(s1) and s1[i] == s3[i + j] and dp[i + 1][j]:
11
dp[i][j] = True
12
if j < len(s2) and s2[j] == s3[i + j] and dp[i][j + 1]:
13
dp[i][j] = True
14
return dp[0][0]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0