feat: added alternative python solutions.
This commit is contained in:
15
longest-palindromic-subsequence/src/alternative-ac.py
Normal file
15
longest-palindromic-subsequence/src/alternative-ac.py
Normal file
@@ -0,0 +1,15 @@
|
||||
n = int(input())
|
||||
s = input().strip()
|
||||
|
||||
s_rev = s[::-1]
|
||||
|
||||
dp = [[0] * (n + 1) for _ in range(n + 1)]
|
||||
|
||||
for i in range(1, n + 1):
|
||||
for j in range(1, n + 1):
|
||||
if s[i - 1] == s_rev[j - 1]:
|
||||
dp[i][j] = dp[i - 1][j - 1] + 1
|
||||
else:
|
||||
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
|
||||
|
||||
print(dp[n][n])
|
||||
Reference in New Issue
Block a user