Skip to content

Commit 6139c9c

Browse files
committed
[LC] feat: palindromic-substring
1 parent 833fda5 commit 6139c9c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

palindromic-substrings/hajunyoo.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def countSubstrings(self, s: str) -> int:
3+
self.count = 0
4+
n = len(s)
5+
6+
def two_pointer_expand(left, right):
7+
while left >= 0 and right < n and s[left] == s[right]:
8+
self.count += 1
9+
left -= 1
10+
right += 1
11+
12+
for i in range(0, n):
13+
# 1, 3, 5 ...
14+
two_pointer_expand(i, i)
15+
# 2, 4, 6 ...
16+
two_pointer_expand(i, i + 1)
17+
18+
return self.count

0 commit comments

Comments
 (0)