# 最长回文子串

<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

```python
class Solution:
	def longestPalindrome(self, s: str) -> str:
		ti = 0
		maxlen = 0
		i = 0
		while i < len(s):
			t = 1
			while t <= i and i + t < len(s):
				if s[i + t] == s[i - t]:
					t += 1
				else:
					break
			t -= 1
			if 2 * t + 1 > maxlen:
				ti = i - t
				maxlen = 2 * t + 1
			i += 1
		i = 0
		while i < len(s):
			t = 1
			while t <= i + 1 and i + t < len(s):
				if s[i - t + 1] == s[i + t]:
					t += 1
				else:
					break
			t -= 1
			if 2 * t > maxlen:
				ti = i - t + 1
				maxlen = 2 * t
			i += 1
		return s[ti:ti+maxlen]
# %%
s = Solution()
print(s.longestPalindrome('babad'))
print(s.longestPalindrome('cbbd'))
```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```