How to use Java to find the longest reply substring
This article introduces the knowledge of "how to use Java to find the longest reply substring". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Given a string s, find the longest palindromic substring in s. You can assume that the maximum length of s is 1000.
Example 1:
Input: "babad" output: "bab" Note: "aba" is also a valid answer.
Example 2:
Input: "cbbd" output: "bb" class Solution: def longestPalindrome (self, s): res = "" for i in range (len (s)): # odd case, like "aba" tmp = self.helper (s, I) if len (tmp) > len (res): res = tmp # even case Like "abba" tmp = self.helper (s, I, iTun1) if len (tmp) > len (res): res = tmp return res # get the longest palindrome, l, r are the middle indexes # from inner to outer def helper (self, s, l, r): while l > = 0 and r < len (s) and s [l] = s [r]: l-= 1 R + = 1 return s [lumb1 r] "how to find the longest reply substring using Java" ends here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!