{"id":2784,"date":"2020-01-16T14:50:46","date_gmt":"2020-01-16T06:50:46","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2784"},"modified":"2020-01-16T14:50:46","modified_gmt":"2020-01-16T06:50:46","slug":"%e3%80%90leetcode%e3%80%910012-%e6%95%b4%e6%95%b0%e8%bd%ac%e7%bd%97%e9%a9%ac%e6%95%b0%e5%ad%97","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2784\/","title":{"rendered":"\u3010LeetCode\u30110012 \u6574\u6570\u8f6c\u7f57\u9a6c\u6570\u5b57"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/integer-to-roman\/\">https:\/\/leetcode-cn.com\/problems\/integer-to-roman\/<\/a><\/p>\n\n\n<p>\u4ee3\u7801\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-\n<em>\n<\/em>class Solution(object):\n    def intToRoman(self, num):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> num: int\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: str\n        \"\"\"\n        <\/em>num_list = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]\n        alpha_list = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']\n        result = ''\n        while num > 0:\n            for i in range(len(num_list)):\n                if num >= num_list[i]:\n                    num -= num_list[i]\n                    result += alpha_list[i]\n                    break\n        return result\n        pass\nif __name__ == '__main__':\n    num = 20\n    print(Solution().intToRoman(num))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u8fd9\u9053\u9898\u5c31\u662f\u4e2a\u7b80\u5355\u7684\u6253\u8868\uff0c\u503c\u5f97\u4e00\u8bf4\u7684\u5c31\u662f\u5c06\u7f57\u9a6c\u6570\u5b57\u4e2d\u7279\u6b8a\u89c4\u5219\u4f5c\u4e3a\u4e00\u822c\u89c4\u5219\u653e\u5165\u5217\u8868\u4e2d\uff0c\u7136\u540e\u4ece\u5927\u5230\u5c0f\u4f9d\u6b21\u8f93\u51fa\u7f57\u9a6c\u6570\u5b57\u5b57\u6bcd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/integer-to-roman\/ [&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":1408,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2784"}],"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=2784"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2784\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2784"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}