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 +} +```