Skip to content

[5] Longest Palindromic Substring

https://leetcode.com/problems/longest-palindromic-substring/description/

  • algorithms
  • Medium (25.75%)
  • Source Code: 5.longest-palindromic-substring.py
  • Total Accepted: 525.1K
  • Total Submissions: 1.9M
  • Testcase Example: '"babad"'

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"

python
class Solution(object):
    def longestPalindrome(self, s):
        """
        :type s: str
        :rtype: str
        """

Last updated: