https://leetcode.com/problems/longest-palindromic-substring/
Algorithm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Input: s
n ← length(s)
max_len ← 0
rst ← ""
if n is 1:
return s
for start ← 0 to n - 2
ends ← all positions whose value is equal to that of start except start index
for end in ends
ss = s[start:end + 1]
if max_len >= length(ss)
break
elif ss is palindromic
max_len ← length(ss)
rst ← ss
if start is (n - 1) - max_len
return rst
return rst
Code
1904ms / 13.7MB
PREVIOUSEtc