Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Java to find the longest reply substring

Shulou Source: shulou.com Published: 2022-06-01 16:32:30 10月04日 Update

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!

Tags: Longest palindromes output content more knowledge examples input practical maximum effective successful next dilemma characters strings actual situation articles cases Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Linux Huawei Shulou Information Microsoft