commit
bf740e370a
|
|
@ -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
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue