Java implements code sharing to find the maximum palindrome string of the current string
Look at the code first
1、 Palindrome judgment of string
Judge whether a string is palindrome
Problem Description: give a string, such as string t = "madam"; To determine whether the string is a palindrome
Method 1: 1. Define two string element pointers (note that Java has no pointer concept), int right = t.length() - 1; int left=0;
2, that is, left starts from the left and right starts from the right. Compare whether the characters are equal in turn. If they are equal, set left + +, right --; Otherwise, the direct return is not a palindrome
code:
Method 2: palindrome strings, such as "madam". If all of them are reversed, their own "madam" is still obtained. After comparing the two strings, if they are equal, they are palindromes
1. Implement a function to reverse the string
2: How to find the maximum palindrome string of a given string
For example, given the string string t = "Google", how to find the longest palindrome substring "Google"
1. The simplest and direct idea is to find out all substrings of the string, then judge whether each substring is a palindrome, record, compare and calculate the palindrome with the maximum length, * the time complexity of the algorithm is O (n ^ 3)
2. The second idea is to judge each character t [i] in the string
Even length substrings centered on T [i], t [i + 1] are palindromes
Is the odd length substring centered on T [i] a palindrome