[LeetCode][Python3] 5. Longest Palindromic Substring
2019. 4. 30. 01:19 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/longest-palindromic-substring/
My Solution :
class Solution:
def longestPalindrome(self, s: str) -> str:
L, R = 0, len(s)
def expand(left, right):
while L <= left and right < R and s[left] == s[right]:
left -= 1
right += 1
return right - left - 1
ans = ''
for i in range(len(s)):
size = max(expand(i, i), expand(i, i+1))
if size > len(ans):
ans = s[i-(size-1)//2:i+1+size//2]
return ans
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 47. Permutations II (0) | 2019.08.18 |
---|---|
[LeetCode][Python3] 1079. Letter Tile Possibilities (0) | 2019.08.16 |
[LeetCode][Python3] 765. Couples Holding Hands (0) | 2019.08.15 |
[LeetCode][Python3] 854. K-Similar Strings (0) | 2019.08.15 |
[LeetCode][Python3] 140. Word Break II (0) | 2019.04.25 |
[LeetCode][Python3] 50. Pow(x, n) (0) | 2019.04.24 |
[LeetCode][Python3] 212. Word Search II (0) | 2019.04.24 |
[LeetCode][Python3] 41. First Missing Positive (0) | 2019.04.23 |
최근에 달린 댓글 최근에 달린 댓글