Участник:Kiranov dmitry/task6

Материал из DISCOPAL
Перейти к: навигация, поиск

ссылка: https://leetcode.com/problems/longest-common-subsequence

class Solution:
   def longestCommonSubsequence(self, text1: str, text2: str) -> int:
       n = len(text1)
       m = len(text2)
       F = [[0] * (m + 1) for i in range(n + 1)]
       for i in range(1, n + 1):
           for j in range(1, m + 1):
               if text1[i - 1] == text2[j - 1]:
                   F[i][j] = F[i - 1][j - 1] + 1 
               else: 
                   F[i][j] = max(F[i - 1][j], F[i][j - 1]) 
       return(F[n][m])