It's the Xinrui Ma

Blog

Longest Palindromic Substring

Posted by in LeetCode on

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"

Solution 1:
Use O(N) time complexity and O(1) space complexity to find the palindromic.
Start from the longest possible substring, once it find a match, return that result