Leetcode Problem solving-longest palindromic Substring

Source: Internet
Author: User

Title: Given A string S, find the longest palindromic substring in S. The maximum length of S is assume, and there exists one unique longest palindromic substring.

Problem solving: Refer to the online great God practice, solve the problem as follows:

classSolution:defget_palindromic (self, S, K, L): S_len=Len (s) whileK >= 0 andL < S_len andS[k] = =S[l]: K-= 1L+ = 1returnS[k+1: l]defLongestpalindrome (self, s): L_palindromic="'         forIinchRange (len (s)): Temp_palindromic1=Self.get_palindromic (S, I, i)ifLen (TEMP_PALINDROMIC1) >Len (l_palindromic): L_palindromic=Temp_palindromic1 Temp_palindromic2= Self.get_palindromic (S, I, i+1)            ifLen (TEMP_PALINDROMIC2) >Len (l_palindromic): L_palindromic=Temp_palindromic2returnL_palindromic

Leetcode Problem solving-longest palindromic Substring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.