Skip to content

Commit b7733cb

Browse files
committed
Time: 177 ms (28.59%), Space: 213 MB (5.58%) - LeetHub
1 parent 2b00973 commit b7733cb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution:
2+
def countSubstrings(self, s: str) -> int:
3+
answer = []
4+
for i in s:
5+
answer.append(i)
6+
7+
def expand(left, right):
8+
9+
while left > 0 and right < len(s) - 1 and s[left] == s[right]:
10+
if s[left] == s[right]:
11+
answer.append(s[left: right + 1])
12+
13+
left -= 1
14+
right += 1
15+
16+
17+
if s[left] == s[right]:
18+
answer.append(s[left : right + 1])
19+
20+
for i in range(1, len(s) - 1):
21+
expand(i - 1, i + 1)
22+
23+
for i in range(1, len(s)):
24+
expand(i - 1, i)
25+
26+
return len(answer)
27+

0 commit comments

Comments
 (0)