We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 93b4acf commit 2d8ab89Copy full SHA for 2d8ab89
palindromic-substrings/evan.py
@@ -0,0 +1,21 @@
1
+class Solution:
2
+ def countSubstrings(self, s: str) -> int:
3
+ def expand_around_center(left: int, right: int) -> int:
4
+ count = 0
5
+
6
+ while left >= 0 and right < len(s) and s[left] == s[right]:
7
+ count += 1
8
+ left -= 1
9
+ right += 1
10
11
+ return count
12
13
+ total_count = 0
14
15
+ for i in range(len(s)):
16
+ # Odd-length palindromes (single character(s[i]) center)
17
+ total_count += expand_around_center(i, i)
18
+ # Even-length palindromes (two character(s[i], s[i+1])s center)
19
+ total_count += expand_around_center(i, i + 1)
20
21
+ return total_count
0 commit comments