Skip to content

Commit

Permalink
Add solution for Palindromic Substrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacknahil committed Aug 22, 2024
1 parent a00daf5 commit 872e5bb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions dp/leetcode/palindromic-substrings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution:
def countSubstrings(self, s: str) -> int:
n=len(s)
count=0
def checker(left,right):
nonlocal count
while left>=0 and right<n:
if s[left]==s[right]:
count+=1
left-=1
right+=1
else:
break
for i in range(n):
checker(i,i)
checker(i,i+1)
return count






0 comments on commit 872e5bb

Please sign in to comment.