{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "3927c7b6932c47789bf5dce8b98e6f25",
  "keywords": "字符串,动态规划",
  "title": "最长回文子串",
  "desc": [
    {
      "content": "\n<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>\t<li><code>1 <= s.length <= 1000</code></li>\t<li><code>s</code> 仅由数字和英文字母（大写和/或小写）组成</li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "class Solution {\n\tpublic String longestPalindrome(String s) {\n\t\tint ti = 0, maxlen = 0, i, t;\n\t\tfor (i = 0; i < s.length(); i++) {\n\t\t\tt = 1;\n\t\t\twhile (t <= i && i + t < s.length()) {\n\t\t\t\tif (s.charAt(i + t) == s.charAt(i - t))\n\t\t\t\t\tt++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt--;\n\t\t\tif (2 * t + 1 > maxlen) {\n\t\t\t\tti = i - t;\n\t\t\t\tmaxlen = 2 * t + 1;\n\t\t\t}\n\t\t}\n\t\tfor (i = 0; i < s.length(); i++) {\n\t\t\tt = 1;\n\t\t\twhile (t <= i + 1 && i + t < s.length()) {\n\t\t\t\tif (s.charAt(i - t + 1) == s.charAt(i + t))\n\t\t\t\t\tt++;\n\t\t\t\telse\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt--;\n\t\t\tif (2 * t > maxlen) {\n\t\t\t\tti = i - t + 1;\n\t\t\t\tmaxlen = 2 * t;\n\t\t\t}\n\t\t}\n\t\treturn s.substring(ti, ti + maxlen);\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-68cfc35ac6174d01bfb5751c70035252",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600470834"
}