Longest Palindromic Substring

Medium

Description

Given a string s, return the longest palindromic substring in s. A palindrome reads the same forward and backward.

Examples

Input:s = "babad"
Output:"bab"
Explanation:

"aba" is also a valid answer.

Input:s = "cbbd"
Output:"bb"
Explanation:

The longest palindromic substring is 'bb'.

Input:s = "racecar"
Output:"racecar"
Explanation:

The entire string 'racecar' is itself a palindrome, so it is the longest palindromic substring with length 7.

Constraints

  • 1 ≤ s.length ≤ 1000
  • s consist of only digits and English letters.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!