mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
Update 0647.回文子串.md
This commit is contained in:
@ -227,6 +227,30 @@ Python:
|
|||||||
|
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
```Go
|
||||||
|
func countSubstrings(s string) int {
|
||||||
|
res:=0
|
||||||
|
dp:=make([][]bool,len(s))
|
||||||
|
for i:=0;i<len(s);i++{
|
||||||
|
dp[i]=make([]bool,len(s))
|
||||||
|
}
|
||||||
|
|
||||||
|
for i:=len(s)-1;i>=0;i--{
|
||||||
|
for j:=i;j<len(s);j++{
|
||||||
|
if s[i]==s[j]{
|
||||||
|
if j-i<=1{
|
||||||
|
res++
|
||||||
|
dp[i][j]=true
|
||||||
|
}else if dp[i+1][j-1]{
|
||||||
|
res++
|
||||||
|
dp[i][j]=true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user