dp
with dimensions [n+1][n][n]
, where n
is the length of the input strings.dp
: for i
from 0
to n-1
, and for j
from 0
to n-1
, set dp[1][i][j]
to true
if s1[i] == s2[j]
, otherwise false
.2
to n
.i
for s1
and j
for s2
.newLength
from 1
to length - 1
.dp[length][i][j]
to true
.dp[n][0][0]
as the final result.