{"id":2787,"date":"2020-01-17T09:39:49","date_gmt":"2020-01-17T01:39:49","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2787"},"modified":"2020-01-17T09:39:49","modified_gmt":"2020-01-17T01:39:49","slug":"%e3%80%90leetcode%e3%80%910013-%e7%bd%97%e9%a9%ac%e6%95%b0%e5%ad%97%e8%bd%ac%e6%95%b4%e6%95%b0","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2787\/","title":{"rendered":"\u3010LeetCode\u30110013 \u7f57\u9a6c\u6570\u5b57\u8f6c\u6574\u6570"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/roman-to-integer\/\">https:\/\/leetcode-cn.com\/problems\/roman-to-integer\/<\/a><\/p>\n\n\n<p>\u4ee3\u7801\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-<em>\n<\/em>class Solution(object):\n    def romanToInt(self, s):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> s: str\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: int\n        \"\"\"\n        <\/em>alpha_num_dict = {\n            'M': 1000,\n            'D': 500,\n            'C': 100,\n            'L': 50,\n            'X': 10,\n            'V': 5,\n            'I': 1\n        }\n        sum = 0\n        for i in range(len(s)):\n            if i &lt; len(s) - 1 and alpha_num_dict[s[i]] &lt; alpha_num_dict[s[i + 1]]:\n                sum -= alpha_num_dict[s[i]]\n            else:\n                sum += alpha_num_dict[s[i]]\n        return sum\nif __name__ == '__main__':\n    s = 'IV'\n    print(Solution().romanToInt(s))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u8fd9\u9053\u9898\u4e5f\u662f\u86ee\u7b80\u5355\u7684\uff0c\u76f4\u63a5\u904d\u5386\u5b57\u7b26\u4e32s\uff0c\u5982\u679c\u524d\u4e00\u4f4d\u6bd4\u540e\u4e00\u4f4d\u5c0f\u5219\u505a\u51cf\u6cd5\uff0c\u53cd\u4e4b\u52a0\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/roman-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":1992,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2787"}],"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=2787"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2787\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2787"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}