Longest Palindromic Substring – LeetCode

Problem

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.

Solution

1. Scan the character from left, and make it current position and center. (need consider cases: abcba and abccba)
2. Around the center, move two pointers, one to left, one to right until it is not Palindrome. Get current Palindrome string
3. Compare to the max length Palindrome, and choose a new max length Palindrome.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

One thought on “Longest Palindromic Substring – LeetCode

  1. Pingback: Longest Substring Without Repeating Characters - LeetCode

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">