蔡晓建

# 参考源码

``````public class Solution {
private String maxString = "";

public String longestPalindrome(String s) {
char[] chars = s.toCharArray();
int length = chars.length;
for (int i = 0; i < length; i++) {
// find longest odd palindrome
findPalindrome(chars, length, i, 0);
// find longest even palindrome
findPalindrome(chars, length, i, 1);
}
return maxString;
}

private void findPalindrome(char[] chars, int length, int i, int shift) {
int left = i;
int right = i + shift;
while (left >= 0 && right < length && chars[left] == chars[right]) {
left--;
right++;
}
if (right - left - 1 > maxString.length()) {
maxString = new String(chars, left + 1, right - left - 1);
}
}
}
``````

### 蔡晓建

[leetcode] Longest Palindromic Substring

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. ht......

jdflyfly
2014/06/24
614
0
[LeetCode] Longest Palindromic Substring

[LeetCode] Longest Palindromic Substring 题目 https://leetcode.com/problems/longest-palindromic-substring/ Given a string s, find the longest palindromic substring in s. You ma......

u013553529
2017/11/26
0
0
leetcode-algorithms-5 Longest Palindromic Substring

leetcode-algorithms-5 Longest Palindromic Substring Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1......

mathli
11/22
0
0
leetcode算法题解(Java版)-2-最长回文子串

kissjz
04/28
0
0
5. Longest Palindromic Substring - LeetCode

LeetCode Problems Solutions question description: 问题描述 Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. 给......

2017/08/18
0
0

5分钟前
0
1
windows环境下搭建rabbitMQ开发环境

windows环境下搭建rabbitMQ开发环境 下载与安装 erlang rabbitmq 是使用erlang语言开发的，所以需要erlang环境； 下载地址 rabbitmq 下载地址 rabbitmq与erlang版本关系 下载之后直接安装即可...

17分钟前
0
0
JVM 中的守护线程

20分钟前
1
0

grace_233
33分钟前
2
0

KMP算法的资料网上已经一大把了，主要用来解决某个文本片段是否包含另一个子串问题。这里假设文本片段的长度n大于子串长度m，如： 文本串为ABCDABGHIJK 子串为 ABCDABE 在传统的暴力解法中当...

FAT_mt
35分钟前
3
0