22 lines
1.7 KiB
Python
22 lines
1.7 KiB
Python
#https://leetcode.com/problems/longest-palindromic-substring/submissions/
|
|
|
|
class Solution:
|
|
def longestPalindrome(self, s: str) -> str:
|
|
longestSub = ""
|
|
for base in range(len(s)):
|
|
for length in range(len(s)-base):
|
|
print(base, length, s[base:len(s)-length])
|
|
if s[base:len(s)-length] == s[base:len(s)-length][::-1]:
|
|
if len(s[base:len(s)-length]) > len(longestSub):
|
|
if base == 0 and length == len(s):
|
|
return s[base:len(s)-length]
|
|
longestSub = s[base:len(s)-length]
|
|
return longestSub
|
|
|
|
def main():
|
|
solution = Solution()
|
|
print(solution.longestPalindrome("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"))
|
|
|
|
if __name__ == '__main__':
|
|
main()
|