package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev
# README
647. Palindromic Substrings
Solution idea
DP
思路与其他回文串的题,尤其是5. Longest Palindromic Substring很像。每找到一个合法的回文串,就在 res
上 +1
.
Time complexity = $O(n^2)$
Space complexity = $O(n^2)$
Two Pointers
中心开花
-
找以
[i]
为中心的合法回文串有多少个 -
找以
[i, i+1]
为中心的合法回文串有多少个 -
把所有的个数加起来
Time complexity = $O(n^2)$
Space complexity = $O(1)$