Skip to content

Instantly share code, notes, and snippets.

@ceth-x86
Created January 7, 2021 06:15
Show Gist options
  • Save ceth-x86/c08b862f24839c68073e53bc2571daf0 to your computer and use it in GitHub Desktop.
Save ceth-x86/c08b862f24839c68073e53bc2571daf0 to your computer and use it in GitHub Desktop.

Revisions

  1. ceth-x86 created this gist Jan 7, 2021.
    12 changes: 12 additions & 0 deletions longest palindromic substring.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    class Solution:
    def longestPalindrome(self, s: str) -> str:
    res = ""
    for i in range(len(s)):
    res = max(self.helper(s, i, i), self.helper(s, i, i+1), res, key=len)
    return res

    def helper(self, s, l, r):
    while 0 <= l and r < len(s) and s[l] == s [r]:
    l -= 1; r += 1
    return s[l+1:r]