题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af
package main
func getLongestPalindrome( A string ) int {
// write code here 暴力
n, ans := len(A), 1
for j := 1; j < n; j++ {
for i := 0; i < j; i++ {
if j-i+1 > ans && isVaildPalindrome(A[i:j+1]) {
ans = j-i+1
}
}
}
return ans
}
func isVaildPalindrome(s string) bool {
i, j := 0, len(s)-1
for ; i < j && s[i] == s[j]; i, j = i+1, j-1 {}
return i >= j
}
查看13道真题和解析

