From dcd7962774eba5e0092c514a26e10d9a7d857719 Mon Sep 17 00:00:00 2001 From: QuinnDK <39618652+QuinnDK@users.noreply.github.com> Date: Tue, 18 May 2021 21:22:33 +0800 Subject: [PATCH] =?UTF-8?q?Update=200516.=E6=9C=80=E9=95=BF=E5=9B=9E?= =?UTF-8?q?=E6=96=87=E5=AD=90=E5=BA=8F=E5=88=97.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0516.最长回文子序列.md | 30 +++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/problems/0516.最长回文子序列.md b/problems/0516.最长回文子序列.md index d7acef99..d2253a4e 100644 --- a/problems/0516.最长回文子序列.md +++ b/problems/0516.最长回文子序列.md @@ -173,7 +173,35 @@ Python: Go: - +```Go +func longestPalindromeSubseq(s string) int { + str:=[]byte(s) + dp:=make([][]int,len(s)) + for i:=0;i=0;j--{ + if str[i]==str[j]{ + if j==i-1{ + dp[j][i]=2 + }else{ + dp[j][i]=dp[j+1][i-1]+2 + } + }else{ + dp[j][i]=Max(dp[j+1][i],dp[j][i-1]) + } + } + } + return dp[0][len(s)-1] +} +func Max(a,b int)int{ + if a>b{ + return a + } + return b +} +```