def numDistinct(self, s: str, t: str) -> int:
n = len(s)
m = len(t)
if n<m:
return 0
count = 0
def check(sub, i, length):
nonlocal count
if i>=n:
return
if length>m:
return
if sub!=t[:length]:
return
if sub==t:
count+=1
return
for j in range(i+1,n):
temp = sub
sub+=s[j]
check(sub, j, length+1)
sub = temp
for i in range(n):
check(s[i], i, 1)
return count
I can't find a way for memoization of this, please help. The question is to find, Given two strings s and t, return the number of distinct subsequences of s which equals t.
A string's subsequence is a new string formed from the original string by deleting some (can be none) of the characters without disturbing the remaining characters' relative positions.