Merge pull request #123 from QuinnDK/添加0647回文子串Go版本

添加0647回文子串Go版本
This commit is contained in:
Carl Sun
2021-05-15 17:12:07 +08:00
committed by GitHub

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
}
```