{"id":1279,"date":"2022-06-04T10:37:43","date_gmt":"2022-06-04T02:37:43","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1279"},"modified":"2022-06-04T10:37:43","modified_gmt":"2022-06-04T02:37:43","slug":"hj85-%e6%9c%80%e9%95%bf%e5%9b%9e%e6%96%87%e5%ad%90%e4%b8%b2return-s-equalsnew-stringbuilders-reverse-tostring","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2022\/06\/04\/hj85-%e6%9c%80%e9%95%bf%e5%9b%9e%e6%96%87%e5%ad%90%e4%b8%b2return-s-equalsnew-stringbuilders-reverse-tostring\/","title":{"rendered":"HJ85 \u6700\u957f\u56de\u6587\u5b50\u4e32return s.equals(new StringBuilder(s).reverse().toString());"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u63cf\u8ff0<\/h2>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32\uff0c\u6c42\u5b83\u7684\u6700\u957f\u56de\u6587\u5b50\u4e32\u7684\u957f\u5ea6\u3002\u6240\u8c13\u56de\u6587\u4e32\uff0c\u6307\u5de6\u53f3\u5bf9\u79f0\u7684\u5b57\u7b26\u4e32\u3002\u6240\u8c13\u5b50\u4e32\uff0c\u6307\u4e00\u4e2a\u5b57\u7b26\u4e32\u5220\u6389\u5176\u90e8\u5206\u524d\u7f00\u548c\u540e\u7f00\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\uff09\u7684\u5b57\u7b26\u4e32<br>\u6570\u636e\u8303\u56f4\uff1a\u5b57\u7b26\u4e32\u957f\u5ea61\u2264<em>s<\/em>\u2264350\u00a0\u8fdb\u9636\uff1a\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(n)\\<em>O<\/em>(<em>n<\/em>)\u00a0\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(n)\\<em>O<\/em>(<em>n<\/em>)\u00a0<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u5165\u63cf\u8ff0\uff1a<\/h3>\n\n\n\n<p>\u8f93\u5165\u4e00\u4e2a\u4ec5\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8f93\u51fa\u63cf\u8ff0\uff1a<\/h3>\n\n\n\n<p>\u8fd4\u56de\u6700\u957f\u56de\u6587\u5b50\u4e32\u7684\u957f\u5ea6<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b1<\/h2>\n\n\n\n<p>\u8f93\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cdabbacc<\/pre>\n\n\n\n<p>\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">4<\/pre>\n\n\n\n<p>\u8bf4\u660e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">abba\u4e3a\u6700\u957f\u7684\u56de\u6587\u5b50\u4e32<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.*;\n\npublic class Main {\n    public static void main(String args&#91;]) {\n        Scanner input = new Scanner(System.in);\n        String s = input.nextLine();\n        int max = 0;\n        \/**\n        *\u53cc\u6307\u9488\u904d\u5386\u627e\u5230\u6700\u957f\u5b50\u4e32\n        *\/\n        for (int i = 0; i &lt; s.length(); i++) {\n            for (int j = s.length(); j > i; j--) {\n                String toBeJuged = s.substring(i, j);\n                if (isPalindromeString(toBeJuged)) {\n                    max = Math.max(max, j - i);\n                }\n            }\n        }\n        System.out.print(max);\n    } \n    \/**\n    *\u5224\u65ad\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u662f\u56de\u6587\u5b57\u7b26\u4e32\u7684\u65b9\u6cd5\n    *\/\n    static boolean isPalindromeString(String s) {\n        return s.equals(new StringBuilder(s).reverse().toString());\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u63cf\u8ff0 \u7ed9\u5b9a\u4e00\u4e2a\u4ec5\u5305\u542b\u5c0f\u5199\u5b57\u6bcd\u7684\u5b57&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1257,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[],"class_list":["post-1279","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1279"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1279\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/1257"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}