Simple Top Down Python Solution


#1
from functools import lru_cache
import sys

class Solution:
    def solve(self, s, t):
        sys.setrecursionlimit(10000)
        @lru_cache(maxsize=10000)
        def lcs(i, j):
            if i >= len(s) or j >= len(t):
                return 0
            
            return 1 + lcs(i + 1, j + 1) if s[i] == t[j] else max(lcs(i + 1, j), lcs(i, j + 1))

        return lcs(0, 0)