Skip to content

Commit 9b9d38c

Browse files
committed
[Leo] 11th Week solutions
1 parent c00280e commit 9b9d38c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

palindromic-substrings/Leo.py

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

0 commit comments

Comments
 (0)