mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user