Skip to content

Commit ca4fdb7

Browse files
author
sejineer
committed
palindromic-substrings solution
1 parent 1743351 commit ca4fdb7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

palindromic-substrings/sejineer.py

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

0 commit comments

Comments
 (0)