Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the longest palindromic substring in java

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report