{"id":38378,"date":"2023-12-11T14:44:17","date_gmt":"2023-12-11T06:44:17","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=38378"},"modified":"2023-12-11T14:44:17","modified_gmt":"2023-12-11T06:44:17","slug":"%e6%89%8b%e5%86%99%e4%bb%a3%e7%a0%81%ef%bc%9a%e5%90%88%e5%b9%b6%e6%9c%89%e5%ba%8f%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/%e6%89%8b%e5%86%99%e4%bb%a3%e7%a0%81%ef%bc%9a%e5%90%88%e5%b9%b6%e6%9c%89%e5%ba%8f%e6%95%b0%e7%bb%84\/","title":{"rendered":"\u624b\u5199\u4ee3\u7801\uff1a\u5408\u5e76\u6709\u5e8f\u6570\u7ec4"},"content":{"rendered":"<p>&#8220;`&#8221;                    \u53c2\u8003\u56de\u7b54\uff1a<\/p>\n<p>\u89e3\u6cd5\u4e00\uff1a\u4ece\u7ed3\u5c3e\u5f00\u59cb\u5f52\u5e76\uff0c\u4e0d\u4f1a\u8986\u76d6\u5143\u7d20\u3002\u4eceA[n+m-1]\u5904\u5f00\u59cb\u5f80\u524d\u4e00\u4e2a\u5143\u7d20\u4e00\u4e2a\u5143\u7d20\u7684\u6c42\uff0c\u6bcf\u6b21\u90fd\u8981\u6bd4\u8f83A[i]\u548cB[j]\u7684\u5927\u5c0f\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8981\u8003\u8651\u5230\uff1a A\u548cB\u6709\u4e00\u4e2a\u4e3a\u7a7a\u65f6\u7684\u60c5\u51b5<\/p>\n<p>&lt;pre&gt;&lt;code&gt;class Solution {<br \/>\npublic:<br \/>\nvoid merge(int A[], int m, int B[], int n) {<br \/>\nint i , j , k ;<br \/>\nfor( i = m &#8211; 1, j = n &#8211; 1, k = n + m -1; k &gt;= 0; &#8211;k)<br \/>\n{<br \/>\nif( i &gt;= 0 &amp;&amp;(j &lt; 0 || A[i] &gt;= B[j]) )<br \/>\nA[k] = A[i&#8211;];<br \/>\nelse<br \/>\nA[k] = B[j&#8211;];<br \/>\n}<br \/>\n}<br \/>\n};<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u89e3\u6cd5\u4e8c\uff1a\u7531\u4e8e\u5408\u5e76\u540eA\u6570\u7ec4\u7684\u5927\u5c0f\u5fc5\u5b9a\u662fm+n\uff0c\u6240\u4ee5\u4ece\u6700\u540e\u9762\u5f00\u59cb\u5f80\u524d\u8d4b\u503c\uff0c\u5148\u6bd4\u8f83A\u548cB\u4e2d\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u5927\u5c0f\uff0c\u628a\u8f83\u5927\u7684\u90a3\u4e2a\u63d2\u5165\u5230m+n-1\u7684\u4f4d\u7f6e\u4e0a\uff0c\u518d\u4f9d\u6b21\u5411\u524d\u63a8\u3002\u5982\u679cA\u4e2d\u6240\u6709\u7684\u5143\u7d20\u90fd\u6bd4B\u5c0f\uff0c\u90a3\u4e48\u524dm\u4e2a\u8fd8\u662fA\u539f\u6765\u7684\u5185\u5bb9\uff0c\u6ca1\u6709\u6539\u53d8\u3002\u5982\u679cA\u4e2d\u7684\u6570\u7ec4\u6bd4B\u5927\u7684\uff0c\u5f53A\u5faa\u73af\u5b8c\u4e86\uff0cB\u4e2d\u8fd8\u6709\u5143\u7d20\u6ca1\u52a0\u5165A\uff0c\u76f4\u63a5\u7528\u4e2a\u5faa\u73af\u628aB\u4e2d\u6240\u6709\u7684\u5143\u7d20\u8986\u76d6\u5230A\u5269\u4e0b\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>&lt;pre&gt;&lt;code&gt;class Solution {<br \/>\npublic:<br \/>\nvoid merge(int A[], int m, int B[], int n) {<br \/>\nint count = m + n &#8211; 1;<br \/>\n&#8211;m; &#8211;n;<br \/>\nwhile (m &gt;= 0 &amp;&amp; n &gt;= 0) A[count&#8211;] = A[m] &gt; B[n] ? A[m&#8211;] : B[n&#8211;];<br \/>\nwhile (n &gt;= 0) A[count&#8211;] = B[n&#8211;];<br \/>\n}<br \/>\n};<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u00a0<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; \u53c2\u8003\u56de\u7b54\uff1a \u89e3\u6cd5\u4e00\uff1a\u4ece\u7ed3\u5c3e\u5f00\u59cb\u5f52\u5e76\uff0c\u4e0d\u4f1a\u8986\u76d6\u5143\u7d20\u3002\u4eceA[n+m-1]\u5904\u5f00\u59cb\u5f80\u524d [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-38378","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/38378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=38378"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/38378\/revisions"}],"predecessor-version":[{"id":38379,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/38378\/revisions\/38379"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=38378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=38378"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=38378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}