Skip to content

Commit 3e65808

Browse files
authored
Update Readme.md
1 parent 48f4a70 commit 3e65808

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Others/214.Shortest-Palindrome/Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
如果我们将s整体逆序写成r,那么```r=B'A'A```.可以发现s的前段和r的后端恰好都是```A'A```.此外,反过来考虑,已知r是s的逆序,并且r的尾端等于s的首端,那么这段相同的字符串一定是个palindrome,即A'A的形式.
66

7-
有了以上两点证明,那么我们就只要找到最大的```i```,使得```s[0:i]==r[len(s)-i:]```即可.
7+
有了以上两点证明,那么我们就只要找到最大的```i```,使得```s[0:i]==r[len(s)-i:]```,即在r中找到最长的后缀,使得其等于s的前缀。实现这个可以有两种方法:1. 暴力尝试这个长度。2. 类似KMP中求后缀数组的方法,计算数组r的suf[i],即r中截止位置i的最长后缀字符串使得恰好是s的前缀字符串。
88

99

1010

11-
[Leetcode Link](https://leetcode.com/problems/shortest-palindrome)
11+
[Leetcode Link](https://leetcode.com/problems/shortest-palindrome)

0 commit comments

Comments
 (0)