Dashboard Temp Share Shortlinks Frames API

HTMLify

LeetCode - Longest Palindromic Substring - Python
Views: 5 | Author: abh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# @leet imports start
# @leet imports end
# Well, solved after 3 years, 3 line change
# @leet start
class Solution:
    def longestPalindrome(self, s: str) -> str:
        lps = ""
        l = len(s)
        for lb in range(0, l+1):
            for ub in range(lb+1, l+1):
                ss = s[lb:ub]
                if ss == ss[::-1] and len(ss) > len(lps):
                    lps = ss
        return lps
# @leet end