{"id":1812,"date":"2022-01-11T16:46:42","date_gmt":"2022-01-11T08:46:42","guid":{"rendered":"http:\/\/139.9.1.231\/?p=1812"},"modified":"2022-01-11T16:46:47","modified_gmt":"2022-01-11T08:46:47","slug":"leetcodeday14","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/11\/leetcodeday14\/","title":{"rendered":"leetcodeday13&#8211; \u7f57\u9a6c\u6570\u5b57\u8f6c\u6574\u6570"},"content":{"rendered":"\n<p>\u7f57\u9a6c\u6570\u5b57\u5305\u542b\u4ee5\u4e0b\u4e03\u79cd\u5b57\u7b26:&nbsp;<code>I<\/code>\uff0c&nbsp;<code>V<\/code>\uff0c&nbsp;<code>X<\/code>\uff0c&nbsp;<code>L<\/code>\uff0c<code>C<\/code>\uff0c<code>D<\/code>&nbsp;\u548c&nbsp;<code>M<\/code>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u5b57\u7b26<\/strong>          <strong>\u6570\u503c<\/strong>\nI             1\nV             5\nX             10\nL             50\nC             100\nD             500\nM             1000<\/code><\/pre>\n\n\n\n<p>\u4f8b\u5982\uff0c \u7f57\u9a6c\u6570\u5b57&nbsp;<code>2<\/code>&nbsp;\u5199\u505a&nbsp;<code>II<\/code>&nbsp;\uff0c\u5373\u4e3a\u4e24\u4e2a\u5e76\u5217\u7684 1 \u3002<code>12<\/code>&nbsp;\u5199\u505a&nbsp;<code>XII<\/code>&nbsp;\uff0c\u5373\u4e3a&nbsp;<code>X<\/code>&nbsp;+&nbsp;<code>II<\/code>&nbsp;\u3002&nbsp;<code>27<\/code>&nbsp;\u5199\u505a&nbsp;&nbsp;<code>XXVII<\/code>, \u5373\u4e3a&nbsp;<code>XX<\/code>&nbsp;+&nbsp;<code>V<\/code>&nbsp;+&nbsp;<code>II<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u7f57\u9a6c\u6570\u5b57\u4e2d\u5c0f\u7684\u6570\u5b57\u5728\u5927\u7684\u6570\u5b57\u7684\u53f3\u8fb9\u3002\u4f46\u4e5f\u5b58\u5728\u7279\u4f8b\uff0c\u4f8b\u5982 4 \u4e0d\u5199\u505a&nbsp;<code>IIII<\/code>\uff0c\u800c\u662f&nbsp;<code>IV<\/code>\u3002\u6570\u5b57 1 \u5728\u6570\u5b57 5 \u7684\u5de6\u8fb9\uff0c\u6240\u8868\u793a\u7684\u6570\u7b49\u4e8e\u5927\u6570 5 \u51cf\u5c0f\u6570 1 \u5f97\u5230\u7684\u6570\u503c 4 \u3002\u540c\u6837\u5730\uff0c\u6570\u5b57 9 \u8868\u793a\u4e3a&nbsp;<code>IX<\/code>\u3002\u8fd9\u4e2a\u7279\u6b8a\u7684\u89c4\u5219\u53ea\u9002\u7528\u4e8e\u4ee5\u4e0b\u516d\u79cd\u60c5\u51b5\uff1a<\/p>\n\n\n\n<ul><li><code>I<\/code>&nbsp;\u53ef\u4ee5\u653e\u5728&nbsp;<code>V<\/code>&nbsp;(5) \u548c&nbsp;<code>X<\/code>&nbsp;(10) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 4 \u548c 9\u3002<\/li><li><code>X<\/code>&nbsp;\u53ef\u4ee5\u653e\u5728&nbsp;<code>L<\/code>&nbsp;(50) \u548c&nbsp;<code>C<\/code>&nbsp;(100) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a 40 \u548c&nbsp;90\u3002&nbsp;<\/li><li><code>C<\/code>&nbsp;\u53ef\u4ee5\u653e\u5728&nbsp;<code>D<\/code>&nbsp;(500) \u548c&nbsp;<code>M<\/code>&nbsp;(1000) \u7684\u5de6\u8fb9\uff0c\u6765\u8868\u793a&nbsp;400 \u548c&nbsp;900\u3002<\/li><\/ul>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u7f57\u9a6c\u6570\u5b57\uff0c\u5c06\u5176\u8f6c\u6362\u6210\u6574\u6570\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>&nbsp;s = \"III\"\n<strong>\u8f93\u51fa:<\/strong> 3<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>&nbsp;s = \"IV\"\n<strong>\u8f93\u51fa:<\/strong> 4<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>&nbsp;s = \"IX\"\n<strong>\u8f93\u51fa:<\/strong> 9<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;4:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>&nbsp;s = \"LVIII\"\n<strong>\u8f93\u51fa:<\/strong> 58\n<strong>\u89e3\u91ca:<\/strong> L = 50, V= 5, III = 3.<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;5:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>&nbsp;s = \"MCMXCIV\"\n<strong>\u8f93\u51fa:<\/strong> 1994\n<strong>\u89e3\u91ca:<\/strong> M = 1000, CM = 900, XC = 90, IV = 4.<\/code><\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li><code>1 &lt;= s.length &lt;= 15<\/code><\/li><li><code>s<\/code>&nbsp;\u4ec5\u542b\u5b57\u7b26&nbsp;<code>('I', 'V', 'X', 'L', 'C', 'D', 'M')<\/code><\/li><li>\u9898\u76ee\u6570\u636e\u4fdd\u8bc1&nbsp;<code>s<\/code>&nbsp;\u662f\u4e00\u4e2a\u6709\u6548\u7684\u7f57\u9a6c\u6570\u5b57\uff0c\u4e14\u8868\u793a\u6574\u6570\u5728\u8303\u56f4&nbsp;<code>[1, 3999]<\/code>&nbsp;\u5185<\/li><li>\u9898\u76ee\u6240\u7ed9\u6d4b\u8bd5\u7528\u4f8b\u7686\u7b26\u5408\u7f57\u9a6c\u6570\u5b57\u4e66\u5199\u89c4\u5219\uff0c\u4e0d\u4f1a\u51fa\u73b0\u8de8\u4f4d\u7b49\u60c5\u51b5\u3002<\/li><li>IL \u548c IM \u8fd9\u6837\u7684\u4f8b\u5b50\u5e76\u4e0d\u7b26\u5408\u9898\u76ee\u8981\u6c42\uff0c49 \u5e94\u8be5\u5199\u4f5c XLIX\uff0c999 \u5e94\u8be5\u5199\u4f5c CMXCIX \u3002<\/li><\/ul>\n\n\n\n<p>\u601d\u8def\uff1a\u4f7f\u7528\u5b57\u5178\uff0c\u904d\u5386s\u5b57\u7b26\u4e32\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc code=start\r\nclass Solution:\r\n    def romanToInt(self, s: str) -> int:\r\r\n        num=0\r\n        j=0\r\n        dicts={\"M\":1000,\"CM\":900,\"D\":500,\"CD\":400,\"C\":100,\"XC\":90,\"L\":50,\"XL\":40,\"X\":10,\"I\":1,\"IV\":4,\"V\":5,\"IX\":9}\r\n        while j&lt;len(s):\r\n            if s&#91;j:j+2]!='' and dicts.get(s&#91;j:j+2])!=None:\r\n                num=num+dicts&#91;s&#91;j:j+2]]\r\n                j=j+2\r\n            else:\r\n                num = num + dicts&#91;s&#91;j]]\r\n                j=j+1\r\n        return num\r\n\r\n        \r\n# @lc code=end<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-182.png\" alt=\"\" class=\"wp-image-1816\" width=\"650\" height=\"229\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-182.png 617w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-182-300x106.png 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7f57\u9a6c\u6570\u5b57\u5305\u542b\u4ee5\u4e0b\u4e03\u79cd\u5b57\u7b26:&nbsp;I\uff0c&nbsp;V\uff0c&nbsp;X\uff0c&nbsp;L\uff0cC\uff0cD&nbsp;\u548c &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/11\/leetcodeday14\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday13&#8211; \u7f57\u9a6c\u6570\u5b57\u8f6c\u6574\u6570<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1812"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=1812"}],"version-history":[{"count":8,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1812\/revisions"}],"predecessor-version":[{"id":1821,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/1812\/revisions\/1821"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=1812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=1812"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=1812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}