{"id":2764,"date":"2020-01-13T10:24:36","date_gmt":"2020-01-13T02:24:36","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2764"},"modified":"2020-01-13T10:24:36","modified_gmt":"2020-01-13T02:24:36","slug":"%e3%80%90leetcode%e3%80%910007-%e6%95%b4%e6%95%b0%e5%8f%8d%e8%bd%ac","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2764\/","title":{"rendered":"\u3010LeetCode\u30110007 \u6574\u6570\u53cd\u8f6c"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/reverse-integer\/\">https:\/\/leetcode-cn.com\/problems\/reverse-integer\/<\/a><\/p>\n\n\n<p>\u4ee3\u7801\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-<br \/>class Solution(object):<br \/>    def reverse(self, x):<br \/>        <em>\"\"\"<br \/><\/em><em>        <\/em><strong><em>:type<\/em><\/strong><em> x: int<br \/><\/em><em>        <\/em><strong><em>:rtype<\/em><\/strong><em>: int<br \/><\/em><em>        \"\"\"<br \/><\/em><em>        <\/em>if x &lt; (-2 ** 31) or x &gt; (2 ** 31 - 1):<br \/>            return 0<br \/>        if x &lt; 0:<br \/>            str_x = str(-x)<br \/>            res = -int(str_x[::-1])<br \/>            if res &lt; (-2 ** 31) or res &gt; (2 ** 31 - 1):<br \/>                return 0<br \/>            return -int(str_x[::-1])<br \/>        str_x = str(x)<br \/>        res = int(str_x[::-1])<br \/>        if res &lt; (-2 ** 31) or res &gt; (2 ** 31 - 1):<br \/>            return 0<br \/>        return res<br \/><br \/><br \/>if __name__ == '__main__':<br \/>    x = 1534236469<br \/>    print(Solution().reverse(x))<br \/><\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u8fd9\u9053\u9898\u6ca1\u5565\u53ef\u8bf4\u7684\uff0c\u662f\u4e2a\u7b80\u5355\u9898\uff0c\u4f46\u662f\u503c\u5f97\u4e00\u8bf4\u7684\u5c31\u662f\u8fd9\u4e2a32\u4f4d\u6709\u7b26\u53f7\u6574\u6570\uff0c\u8d85\u8fc7\u7b97\u79fb\u9664\uff0c\u9700\u8981\u5728\u6bcf\u6b21\u8fd4\u56de\u94b1\u5224\u65ad\u662f\u5426\u53d1\u751f\u6ea2\u51fa\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/reverse-integer\/  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10],"tags":[],"views":1445,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2764"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2764"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2764\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2764"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}