From e75f76466952eb9091334c05bb1bf0cba8b16329 Mon Sep 17 00:00:00 2001 From: Min Date: Wed, 30 Nov 2022 23:04:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A00005.=E6=9C=80=E9=95=B7?= =?UTF-8?q?=E5=9B=9E=E6=96=87=E5=AD=90=E4=B8=B2C#=20=E5=8B=95=E6=85=8B?= =?UTF-8?q?=E8=A6=8F=E5=89=87=E7=9A=84=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0005.最长回文子串.md | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/problems/0005.最长回文子串.md b/problems/0005.最长回文子串.md index 62c2cbde..84d8d835 100644 --- a/problems/0005.最长回文子串.md +++ b/problems/0005.最长回文子串.md @@ -615,6 +615,38 @@ char * longestPalindrome(char * s){ } ``` +C#: + +動態規則: +```c# +public class Solution { + + public string LongestPalindrome(string s) { + bool[,] dp = new bool[s.Length, s.Length]; + int maxlenth = 0; + int left = 0; + int right = 0; + for(int i = s.Length-1 ; i>=0; i--){ + for(int j = i; j maxlenth){ + maxlenth = j-i+1; + left = i; + right = j; + } + } + } + return s.Substring(left, maxlenth); + } +} +``` +