MCPcopy Create free account
hub / github.com/Ayush7614/Daily-Coding-DS-ALGO-Practice / lcs

Function lcs

Leetcode/Python/shortest_supersequence.py:18–50  ·  view source on GitHub ↗
(X, Y, m, n)

Source from the content-addressed store, hash-verified

16
17#to find lcs.
18def lcs(X, Y, m, n):
19
20 L = [[0] * (n + 2) for i in range(m + 2)]
21
22
23
24
25 for i in range(m + 1):
26
27
28 for j in range(n + 1):
29
30
31 if (i == 0 or j == 0):
32
33 L[i][j] = 0
34
35
36 elif (X[i - 1] == Y[j - 1]):
37
38 L[i][j] = L[i - 1][j - 1] + 1
39
40
41 else:
42
43 L[i][j] = max(L[i - 1][j],
44
45 L[i][j - 1])
46
47
48
49
50 return L[m][n]
51
52
53A =input()

Callers 1

shortestSupSeqFunction · 0.70

Calls 1

maxFunction · 0.50

Tested by

no test coverage detected