LeetCode-5. Longest Palindromic Substring

原文链接: https://blog.csdn.net/small__snail__5/article/details/80310615

5. Longest Palindromic Substring

Medium

4380400FavoriteShare

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Example 1:

Input: "babad"
Output: "bab"
Note: "aba" is also a valid answer.

Example 2:

Input: "cbbd"
Output: "bb"

 

这题的状态转移方程实在是没想明白,看来好久解析才看懂,附上博主原文地址

先附上作者原文地址:https://blog.csdn.net/small__snail__5/article/details/80310615

 

#include 
#include 
#include 
using namespace std;


class Solution {
public:
    string longestPalindrome(string s) {
        int len = s.length();
        int **dp = new int*[len+1];
        for(int i=0;i j+i-1 ----> 即当i<2的时候才有可能满足 j+1 > j+i-1*/
        for(int j=0;jlongestPalindrome(str);
    cout<

 

你可能感兴趣的:(算法,C++,LeetCode)