{"id":2408,"date":"2022-01-26T14:30:30","date_gmt":"2022-01-26T06:30:30","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2408"},"modified":"2022-01-26T14:30:31","modified_gmt":"2022-01-26T06:30:31","slug":"leetcodeday88","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/26\/leetcodeday88\/","title":{"rendered":"leetcodeday88 &#8211;\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e24\u4e2a\u6309&nbsp;<strong>\u975e\u9012\u51cf\u987a\u5e8f<\/strong>&nbsp;\u6392\u5217\u7684\u6574\u6570\u6570\u7ec4&nbsp;<code>nums1<\/code><em>&nbsp;<\/em>\u548c&nbsp;<code>nums2<\/code>\uff0c\u53e6\u6709\u4e24\u4e2a\u6574\u6570&nbsp;<code>m<\/code>&nbsp;\u548c&nbsp;<code>n<\/code>&nbsp;\uff0c\u5206\u522b\u8868\u793a&nbsp;<code>nums1<\/code>&nbsp;\u548c&nbsp;<code>nums2<\/code>&nbsp;\u4e2d\u7684\u5143\u7d20\u6570\u76ee\u3002<\/p>\n\n\n\n<p>\u8bf7\u4f60&nbsp;<strong>\u5408\u5e76<\/strong>&nbsp;<code>nums2<\/code><em>&nbsp;<\/em>\u5230&nbsp;<code>nums1<\/code>&nbsp;\u4e2d\uff0c\u4f7f\u5408\u5e76\u540e\u7684\u6570\u7ec4\u540c\u6837\u6309&nbsp;<strong>\u975e\u9012\u51cf\u987a\u5e8f<\/strong>&nbsp;\u6392\u5217\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u6700\u7ec8\uff0c\u5408\u5e76\u540e\u6570\u7ec4\u4e0d\u5e94\u7531\u51fd\u6570\u8fd4\u56de\uff0c\u800c\u662f\u5b58\u50a8\u5728\u6570\u7ec4&nbsp;<code>nums1<\/code>&nbsp;\u4e2d\u3002\u4e3a\u4e86\u5e94\u5bf9\u8fd9\u79cd\u60c5\u51b5\uff0c<code>nums1<\/code>&nbsp;\u7684\u521d\u59cb\u957f\u5ea6\u4e3a&nbsp;<code>m + n<\/code>\uff0c\u5176\u4e2d\u524d&nbsp;<code>m<\/code>&nbsp;\u4e2a\u5143\u7d20\u8868\u793a\u5e94\u5408\u5e76\u7684\u5143\u7d20\uff0c\u540e&nbsp;<code>n<\/code>&nbsp;\u4e2a\u5143\u7d20\u4e3a&nbsp;<code>0<\/code>&nbsp;\uff0c\u5e94\u5ffd\u7565\u3002<code>nums2<\/code>&nbsp;\u7684\u957f\u5ea6\u4e3a&nbsp;<code>n<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3\n<strong>\u8f93\u51fa\uff1a<\/strong>[1,2,2,3,5,6]\n<strong>\u89e3\u91ca\uff1a<\/strong>\u9700\u8981\u5408\u5e76 [1,2,3] \u548c [2,5,6] \u3002\n\u5408\u5e76\u7ed3\u679c\u662f [<em><strong>1<\/strong><\/em>,<em><strong>2<\/strong><\/em>,2,<em><strong>3<\/strong><\/em>,5,6] \uff0c\u5176\u4e2d\u659c\u4f53\u52a0\u7c97\u6807\u6ce8\u7684\u4e3a nums1 \u4e2d\u7684\u5143\u7d20\u3002<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=88 lang=python3\r\n#\r\n# &#91;88] \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def merge(self, nums1: List&#91;int], m: int, nums2: List&#91;int], n: int) -> None:\r\n        \"\"\"\r\n        Do not return anything, modify nums1 in-place instead.\r\n        \"\"\"\r\n        nums3=nums1&#91;0:m]\r\n        k=0\r\n        j=0\r\n        for i in range(m+n):\r\n            if k&lt;n and j&lt;m:\r\n                if nums2&#91;k]&lt;nums3&#91;j]:\r\n                    nums1&#91;i]=nums2&#91;k]\r\n                    k=k+1\r\n                else:\r\n                    nums1&#91;i]=nums3&#91;j]\r\n                    j=j+1\r\n            elif k&lt;n:\r\n                nums1&#91;i]=nums2&#91;k]\r\n                k=k+1\r\n            else:\r\n                nums1&#91;i]=nums3&#91;j]\r\n                j=j+1\r\n\r\n\r\n\r\n# @lc code=end<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"863\" height=\"217\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-295.png\" alt=\"\" class=\"wp-image-2410\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-295.png 863w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-295-300x75.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-295-768x193.png 768w\" sizes=\"(max-width: 863px) 100vw, 863px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e24\u4e2a\u6309&nbsp;\u975e\u9012\u51cf\u987a\u5e8f&nbsp;\u6392\u5217\u7684\u6574\u6570\u6570\u7ec4&nbsp;nums1&nbsp;\u548c&nbsp;nu &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/26\/leetcodeday88\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday88 &#8211;\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u6570\u7ec4<\/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\/2408"}],"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=2408"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2408\/revisions"}],"predecessor-version":[{"id":2411,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2408\/revisions\/2411"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2408"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}