How to realize the longest palindromic substring in java
This article is about how to achieve the longest palindrome substring in java. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
longest palindromic substring
Given a string s, find the longest palindrome substring in s.
Link: leetcode-cn.com/problems/longest-palindromic-substring
Example 1: Input: s = "bad" Output: "bab" Explanation: "aba" is also the answer to the question. Example 2: Input: s = "cbbd" Output: "bb" Example 3: Input: s = "a" Output: "a" Example 4: Input: s = "ac" Output: "a"//The solution seen in the comment area is simple and easy to understand and efficient. class Solution { public String longestPalindrome(String s) { if(s.length() ==1){ return s; } // arr Save the starting and ending subscripts of palindrome char[] arr = s.toCharArray(); int[] res = new int[2]; //palindrome is the same in the middle, left-right symmetrical string, first determine the middle symmetrical part, and then expand to both sides. for(int i=0;i