5. Longest Palindromic Substring

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"

马拉车算法理解;

class Solution {
public:
    string longestPalindrome(string s) {
       
     string a="$#";
     for(int i=0;ii ?min(p[2*id-i],right-i):1;      
       
       while(a[i+p[i]]==a[i-p[i]])
           ++p[i];
       
       if(right

 

你可能感兴趣的:(LeetCode)