Skip to content

Commit 15a60ed

Browse files
Solve : Palindromic Substrings
1 parent e7e5e2b commit 15a60ed

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def countSubstrings(self, s):
3+
count = 0
4+
for center in range(len(s)):
5+
left, right = center, center
6+
while left >= 0 and right < len(s) and s[left] == s[right]:
7+
count += 1
8+
left -= 1
9+
right += 1
10+
left, right = center, center + 1
11+
while left >= 0 and right < len(s) and s[left] == s[right]:
12+
count += 1
13+
left -= 1
14+
right += 1
15+
return count

0 commit comments

Comments
 (0)