{"id":2766,"date":"2020-01-13T10:50:05","date_gmt":"2020-01-13T02:50:05","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2766"},"modified":"2020-01-13T10:50:05","modified_gmt":"2020-01-13T02:50:05","slug":"%e3%80%90leetcode%e3%80%910008-%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%ac%e6%8d%a2%e6%95%b4%e6%95%b0-atoi","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2766\/","title":{"rendered":"\u3010LeetCode\u30110008 \u5b57\u7b26\u4e32\u8f6c\u6362\u6574\u6570 (atoi)"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/string-to-integer-atoi\/\">https:\/\/leetcode-cn.com\/problems\/string-to-integer-atoi\/<\/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 myAtoi(self, str):<br \/>        <em>\"\"\"<br \/><\/em><em>        <\/em><strong><em>:type<\/em><\/strong><em> str: str<br \/><\/em><em>        <\/em><strong><em>:rtype<\/em><\/strong><em>: int<br \/><\/em><em>        \"\"\"<br \/><\/em><em>        <\/em>import re<br \/>        return max(min(int(*re.findall('^[\\+\\-]?\\d+', str.lstrip())), 2**31 - 1), -2**31)<br \/><br \/><br \/>if __name__ == '__main__':<br \/>    s = '  -4193 with words'<br \/>    print(Solution().myAtoi(s))<br \/>    pass<br \/><\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u8fd9\u9053\u9898\u6bd4\u8f83\u7b80\u5355\uff0c\u6b63\u5219\u4e00\u4e0b\u524d\u51e0\u4e2a\u5339\u914d\u9879\u7136\u540e\u8f6c\u6210int\u51fd\u6570\u5373\u53ef\u3002<\/p>\n\n\n<p>\u5bf9\u4e8e\u6b63\u5219\uff0c\u2018^[\\+\\-]?\\d+\u2019\uff0c\u524d\u7f6e\u5339\u914d+\u6216\u8005-\u7b26\u53f7\uff0c\u7136\u540e\u4f7f\u7528\u975e\u8d2a\u5a6a\u6a21\u5f0f\uff0c\u4e5f\u5c31\u662f\u53ea\u5339\u914d\u5c3d\u53ef\u80fd\u5c11\u4e2a\uff0c\u7136\u540e\u5339\u914d\u6570\u5b57\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/string-to-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":1494,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2766"}],"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=2766"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2766\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2766"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}