Skip to content

Commit 052d112

Browse files
committed
solve: palindromic-substrings
1 parent f770374 commit 052d112

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

palindromic-substrings/Raft.py

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

0 commit comments

Comments
 (0)