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 bae7af9 commit d96b82fCopy full SHA for d96b82f
palindromic-substrings/dm.py
@@ -0,0 +1,23 @@
1
+class Solution:
2
+ def countPalindrome(self, s: str, left: int, right: int) -> int:
3
+ result = 0
4
+
5
+ while left >= 0 and right < len(s) and s[left] == s[right]:
6
+ result += 1
7
+ left -= 1
8
+ right += 1
9
10
+ return result
11
12
+ def countSubstrings(self, s: str) -> int:
13
+ total_count = 0
14
15
+ for i in range(len(s)):
16
+ left = right = i
17
+ total_count += self.countPalindrome(s, left, right)
18
19
+ for i in range(len(s) - 1):
20
+ left, right = i, i + 1
21
22
23
+ return total_count
0 commit comments