All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 10, 2024
Last updated : July 10, 2024
Related Topics : Two Pointers, String, Dynamic Programming
Acceptance Rate : 70.346 %
class Solution:
def countSubstrings(self, s: str) -> int:
counter = 0
for i in range(len(s)) :
offset = 0
while 0 <= i - offset \
and i + offset < len(s) \
and s[i - offset] == s[i + offset] :
offset += 1
counter += 1
for i in range(len(s) - 1) :
offset = 0
while 0 <= i - offset \
and i + offset + 1 < len(s) \
and s[i - offset] == s[i + offset + 1] :
offset += 1
counter += 1
return counter