[Classic] palindrome problem (iii)

Source: Internet
Author: User

Longest palindromic Substring longest palindrome substring

Given a string S, find the longest palindromic substring in s. The maximum length of S is assume, and there exists one unique longest palindromic substring.

General practice, Dynamic Planning O (n^2) is able to directly produce results, the length from small to large arrangement, you can record the maximum value of the edge motion.

Shortest palindrome Shortest palindrome generation

Given A string S, you is allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.

For example:

Given "aacecaaa" , return "aaacecaaa" .

Given "abcd" , return "dcbabcd" .

Common practice, that is to find the longest palindrome from scratch, the complexity of O (n^2);

In fact, the classic algorithm for finding the longest palindrome substring centered on a point is the manacher algorithm, with the complexity of O (N), which can be used to find substrings centered on each point in the string. The Manacher algorithm can refer to http://blog.csdn.net/ggggiqnypgjg/article/details/6645824/

[Classic] palindrome problem (iii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.