Update 0647.回文子串.md

This commit is contained in:
QuinnDK
2021-05-14 19:40:41 +08:00
committed by GitHub
parent cf42d80efc
commit a838937b6d

View File

@ -227,6 +227,30 @@ Python
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
}
```