Palindrome
5. Longest Palindromic Substring
class Solution:
def longestPalindrome(self, s: str) -> str:
ans = ''
for i in range(len(s)):
str1 = self.helper(s, i, i)
str2 = self.helper(s, i, i+1)
cand = str1 if len(str1) > len(str2) else str2
if len(cand) > len(ans):
ans = cand
return ans
def helper(self, s, l, r):
while l >= 0 and r < len(s) and s[l] == s[r]:
l-=1
r+=1
return s[l+1:r]
647. Palindromic Substrings
131. Palindrome Partitioning
132. Palindrome Partitioning II
267. Palindrome Permutation II
214. Shortest Palindrome
516. Palindromic Subsequence
1312. Minimum Insertion Steps to Make a String Palindrome
1297. Maximum Number of Occurrences of a Substring
Last updated