5. Longest Palindromic Substring
[Medium] “Given a string s, find the longest palindromic substring in s."
Note: old solution, should review (TODO:
)
Python3:
class Solution:
def longestPalindrome(self, s: str) -> str:
max_ss = {}
if s == "":
return ""
elif len(s) == 1:
return s
else:
for i in range(0, len(s)):
for j in range(i + 1, len(s) + 1):
ss = s[i:j]
if ss == ss[::-1]:
max_ss[len(ss)] = ss
return max_ss[max(max_ss.keys())]