diff --git a/algorithms/CPlusPlus/Dynamic-Programming/Longest_Palindromic_Substring.cpp b/algorithms/CPlusPlus/Dynamic-Programming/Longest_Palindromic_Substring.cpp new file mode 100644 index 00000000..5c006b0f --- /dev/null +++ b/algorithms/CPlusPlus/Dynamic-Programming/Longest_Palindromic_Substring.cpp @@ -0,0 +1,50 @@ +class Solution +{ +public: + string longestPalindrome(string s) + { + int n=s.size(); + + //dp[i][j] will be false if substring s[i..j] is not palindrome, Else true + vector> dp(n, vector (n,false)); + + //All substrings of length 1 are palindromes + for(int i=0; ilenMax) + { + lenMax = k; + start=i; + } + } + } + } + + return s.substr(start, lenMax); //print sub-string from start to lenMax + } +};