{"id":96,"date":"2017-07-26T19:57:04","date_gmt":"2017-07-26T11:57:04","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=96"},"modified":"2018-11-27T16:09:15","modified_gmt":"2018-11-27T08:09:15","slug":"9-palindrome-number","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=96","title":{"rendered":"9. Palindrome Number"},"content":{"rendered":"<p>Determine whether an integer is a palindrome. An integer\u00a0is\u00a0a\u00a0palindrome when it\u00a0reads the same backward as forward.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre><strong>Input:<\/strong> 121\r\n<strong>Output:<\/strong> true\r\n<\/pre>\n<p><strong>Example 2:<\/strong><\/p>\n<pre><strong>Input:<\/strong> -121\r\n<strong>Output:<\/strong> false\r\n<strong>Explanation:<\/strong> From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.\r\n<\/pre>\n<p><strong>Example 3:<\/strong><\/p>\n<pre><strong>Input:<\/strong> 10\r\n<strong>Output:<\/strong> false\r\n<strong>Explanation:<\/strong> Reads 01 from right to left. Therefore it is not a palindrome.\r\n<\/pre>\n<p><strong>Follow up:<\/strong><\/p>\n<p>Coud you solve\u00a0it without converting the integer to a string?<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def isPalindrome(self, x):\r\n        &quot;&quot;&quot;\r\n        :type x: int\r\n        :rtype: bool\r\n        &quot;&quot;&quot;\r\n        if x &lt; 0:\r\n            return False\r\n        elif x == 0:\r\n            return True\r\n        temp = x\r\n        flag = 0\r\n        while x != 0:\r\n            flag = flag*10 + x % 10\r\n            x \/= 10\r\n        if flag == temp:\r\n            return True\r\n        else:\r\n            return False\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Determine whether an integer is a palindrome. An intege<a href=\"https:\/\/www.ccagml.com\/?p=96\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">9. Palindrome Number<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/96"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=96"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/96\/revisions"}],"predecessor-version":[{"id":98,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/96\/revisions\/98"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}