프로그래밍/LeetCode
[LeetCode][Python3] 647. Palindromic Substrings
snoopybox
2019. 9. 25. 00:37
Problem :
https://leetcode.com/problems/palindromic-substrings/
My Solution :
class Solution:
def countSubstrings(self, s):
def count_palindrome(s, left, right):
count = 0
while 0 <= left and right < len(s) and s[left] == s[right]:
count += 1
left -= 1
right += 1
return count
ans = 0
for i in range(len(s)):
ans += count_palindrome(s, i, i)
ans += count_palindrome(s, i, i+1)
return ans