Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def countSubstrings(self, s: str) -> int:
- n = len(s)
- dp = [[False] * n for _ in range(n)]
- res = 0
- for i in range(n):
- dp[i][i] = True
- res += 1
- if i + 1 < n and s[i] == s[i+1]:
- dp[i][i+1] = True
- res += 1
- for i in range(n-2, -1, -1):
- for j in range(i+1, n):
- if s[i] == s[j] and dp[i+1][j-1]:
- dp[i][j] = True
- res += 1
- return res
Advertisement
Add Comment
Please, Sign In to add comment