Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.24 KB

_647. Palindromic Substrings.md

File metadata and controls

50 lines (36 loc) · 1.24 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 10, 2024

Last updated : July 10, 2024


Related Topics : Two Pointers, String, Dynamic Programming

Acceptance Rate : 70.346 %


Solutions

Python

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