u
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package top100liked
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// https://leetcode.cn/problems/longest-palindromic-substring/?envType=study-plan-v2&envId=top-100-liked
|
||||
// 5. 最长回文子串
|
||||
//
|
||||
// 给你一个字符串 `s`,找到 `s` 中最长的 回文 子串。
|
||||
// 示例 1:
|
||||
// 输入:s = "babad"
|
||||
// 输出:"bab"
|
||||
// 解释:"aba" 同样是符合题意的答案。
|
||||
// 示例 2:
|
||||
// 输入:s = "cbbd"
|
||||
// 输出:"bb"
|
||||
//
|
||||
// 提示:
|
||||
// - `1 <= s.length <= 1000`
|
||||
// - `s` 仅由数字和英文字母组成
|
||||
//
|
||||
func longestPalindrome(s string) string {
|
||||
|
||||
}
|
||||
|
||||
func TestLongestPalindrome(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
s string
|
||||
want string
|
||||
}{
|
||||
{"example1", "babad", "bab"},
|
||||
{"example2", "cbbd", "bb"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
got := longestPalindrome(c.s)
|
||||
if got != c.want {
|
||||
t.Errorf("got %v, want %v", got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user