class Solution: def LCS(self , str1 , str2 ): # write code here l1, l2 = len(str1), len(str2) dp = [['' for _ in range(l2 + 1)] for _ in range(l1 + 1)] ans = '' for i in range(l1): for j in range(l2): if str1[i] == str2[j]: dp[i+1][j+1] = dp[i][j] + str1[i] if len(dp[i+1][j+1]) > len(ans): ans = dp[i+1][j+1] return ans