# 最长回文子串

<p>给你一个字符串 <code>s</code>，找到 <code>s</code> 中最长的回文子串。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>s = "babad"<strong><br />输出：</strong>"bab"<strong><br />解释：</strong>"aba" 同样是符合题意的答案。</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>s = "cbbd"<strong><br />输出：</strong>"bb"</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>s = "a"<strong><br />输出：</strong>"a"</pre><p><strong>示例 4：</strong></p><pre><strong>输入：</strong>s = "ac"<strong><br />输出：</strong>"a"</pre><p> </p><p><strong>提示：</strong></p><ul>	<li><code>1 <= s.length <= 1000</code></li>	<li><code>s</code> 仅由数字和英文字母（大写和/或小写）组成</li></ul>

## template

```java
class Solution {
	public String longestPalindrome(String s) {
		int ti = 0, maxlen = 0, i, t;
		for (i = 0; i < s.length(); i++) {
			t = 1;
			while (t <= i && i + t < s.length()) {
				if (s.charAt(i + t) == s.charAt(i - t))
					t++;
				else
					break;
			}
			t--;
			if (2 * t + 1 > maxlen) {
				ti = i - t;
				maxlen = 2 * t + 1;
			}
		}
		for (i = 0; i < s.length(); i++) {
			t = 1;
			while (t <= i + 1 && i + t < s.length()) {
				if (s.charAt(i - t + 1) == s.charAt(i + t))
					t++;
				else
					break;
			}
			t--;
			if (2 * t > maxlen) {
				ti = i - t + 1;
				maxlen = 2 * t;
			}
		}
		return s.substring(ti, ti + maxlen);
	}
}
```

## 答案

```java

```

## 选项

### A

```java

```

### B

```java

```

### C

```java

```