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