diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-05-28 10:29:13 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2024-05-28 10:29:13 +0200 |
commit | f05d888a0b621ca4e99e2b0fb6e23c097006fe41 (patch) | |
tree | eebbb2489144112d3288393e354d19375a0aa088 /progs/a610.py |
Init
Diffstat (limited to 'progs/a610.py')
-rw-r--r-- | progs/a610.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/progs/a610.py b/progs/a610.py new file mode 100644 index 0000000..0d349ee --- /dev/null +++ b/progs/a610.py @@ -0,0 +1,15 @@ +def lps(str):
+ n = len(str)
+ L = [[0 for x in range(n)] for x in range(n)]
+ for i in range(n):
+ L[i][i] = 1
+ for cl in range(2, n+1):
+ for i in range(n-cl+1):
+ j = i+cl-1
+ if str[i] == str[j] and cl == 2:
+ L[i][j] = 2
+ elif str[i] == str[j]:
+ L[i][j] = L[i+1][j-1] + 2
+ else:
+ L[i][j] = max(L[i][j-1], L[i+1][j]);
+ return L[0][n-1]
\ No newline at end of file |