func longestPalindrome(s string) string {
result := ""
for i:=0; i < len(s); i++{
leftStr := expandStr(s,i,i)
rightStr := expandStr(s,i,i+1)
if len(leftStr) > len(result){
result = leftStr
}
if len(rightStr) > len(result){
result = rightStr
}
}
return result
}
func expandStr(s string, left,right int) string{
for ;left > -1 && right < len(s) && s[left] == s[right];{
left--
right++
}
return s[left+1:right]
}
力扣算法17-最长回文子串
最新推荐文章于 2023-01-16 22:52:44 发布