class Solution:
def longestCommonSubsequence(self, text1: str, text2: str) -> int:
memo = {}
def helper(i, j):
if (i, j) not in memo:
if i == len(text1) or j == len(text2):
memo[(i, j)] = 0
elif text1[i] == text2[j]:
memo[(i, j)] = 1 + helper(i + 1, j + 1)
else:
memo[(i, j)] = max(helper(i + 1, j), helper(i, j + 1))
return memo[(i, j)]