{"id":742,"date":"2022-06-20T08:22:21","date_gmt":"2022-06-20T08:22:21","guid":{"rendered":"https:\/\/blog.liuyingjie.com.cn\/?p=742"},"modified":"2023-08-13T08:09:44","modified_gmt":"2023-08-13T08:09:44","slug":"9-palindrome-number","status":"publish","type":"post","link":"https:\/\/blog.liuyingjie.com.cn\/?p=742","title":{"rendered":"9. \u56de\u6587\u6570"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u65b9\u6cd5\u4e00\uff1a<\/h3>\n\n\n\n<p>\u53cd\u8f6c\u4e00\u534a\u6570\u5b57\uff1a\u4f8b\u5982\u8f93\u51651331\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u5b57\u201c13<strong>31<\/strong>\u201d\u7684\u540e\u534a\u90e8\u5206\u4ece\u201c31\u201d\u53cd\u8f6c\u6210\u201c13\u201d\u5728\u548c\u524d\u534a\u90e8\u5206\u8fdb\u884c\u6bd4\u8f83\uff0c\u5982\u679c\u4e8c\u8005\u76f8\u540c\u6211\u4eec\u5c31\u5f97\u77e5\u6570\u5b57\u201c1331\u201d\u662f\u56de\u6587\u6570<\/p>\n\n\n\n<p>C \u4ee3\u7801\u89e3\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">#include&lt;stdbool.h&gt;\n\nbool isPalindrome(int x){\n    \/\/ \u7279\u6b8a\u60c5\u51b5\u5904\u7406\uff1a\u5982\u679c x \u662f\u8d1f\u6570\u6216\u8005\u672b\u5c3e\u662f 0 \u7684\u975e\u96f6\u6570\uff0c\u5219\u4e0d\u53ef\u80fd\u662f\u56de\u6587\u6570\n    if (x &lt; 0 || (x != 0 &amp;&amp; x % 10 == 0)){\n        return false;\n    }\n\n    long reversed_num = 0;\n    int original_x = x;\n\n    \/\/\u53cd\u8f6c x \u7684\u4e00\u534a\n    while (x &gt; 0){\n        int digit = x % 10;\n        reversed_num = reversed_num * 10 + digit;\n        x \/= 10;\n    }\n\n    \/\/ \u5982\u679c\u539f\u59cb\u6570\u5b57\u957f\u5ea6\u662f\u5947\u6570\uff0c\u53bb\u6389\u6700\u540e\u4e00\u4f4d\n    if (original_x == reversed_num || original_x == reversed_num \/ 10){\n        return true;\n    } else {\n        return false;\n    }\n}<\/code><\/pre>\n\n\n\n<p>Python3 \u4ee3\u7801\u89e3\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">class Solution:\n    def isPalindrome(self, x: int) -&gt; bool:\n        x = str(x)\n        if x == x[::-1]:\n            return True\n        else:\n            return False<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.liuyingjie.com.cn\/wp-content\/uploads\/2022\/06\/9.\u56de\u6587\u6570.png\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>Source: LeetCode\uff08The title reproduced in this blog is for personal study use only\uff09<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65b9\u6cd5\u4e00\uff1a \u53cd\u8f6c\u4e00\u534a\u6570\u5b57\uff1a\u4f8b\u5982\u8f93\u51651331\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u5b57\u201c1331\u201d\u7684\u540e\u534a\u90e8\u5206\u4ece\u201c31\u201d\u53cd\u8f6c\u6210\u201c13\u201d\u5728\u548c\u524d\u534a &hellip; <a href=\"https:\/\/blog.liuyingjie.com.cn\/?p=742\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">9. \u56de\u6587\u6570<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-742","post","type-post","status-publish","format-standard","hentry","category-leetcode"],"_links":{"self":[{"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/742","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=742"}],"version-history":[{"count":15,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/742\/revisions"}],"predecessor-version":[{"id":985,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/742\/revisions\/985"}],"wp:attachment":[{"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}