{"id":1882,"date":"2023-09-24T14:49:38","date_gmt":"2023-09-24T06:49:38","guid":{"rendered":"https:\/\/white-night.club\/?p=1882"},"modified":"2023-11-09T11:07:52","modified_gmt":"2023-11-09T03:07:52","slug":"pg3","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/09\/24\/pg3\/","title":{"rendered":"Vector\uff1aReturn{ }"},"content":{"rendered":"\n<p>leetcode\u5237\u9898\u7684\u65f6\u5019\u770b\u5230\u4e86\uff0c\u89c9\u5f97\u6bd4\u8f83\u6709\u610f\u601d\u5c31\u8bb0\u5f55\u4e00\u4e0b\u5427\u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>return { };<\/p>\n<cite><em>\u590d\u5236\u5217\u8868\u521d\u59cb\u5316\uff08Copy-list-initialization\uff09<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5148\u6765\u770b\u6bb5\u4ee3\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vector&lt;int&gt;Return(vector&lt;int&gt;nums)\n{\n\tif (!nums.empty()&amp;&amp;nums.size()&gt;2)\n\t{\n\t\treturn {nums&#91;1],nums&#91;2]};\n\t}\n}<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d<em>\u201c return {nums[1],nums[2]}; <\/em>\u201d\u8fd9\u91cc\u6d89\u53ca\u5230\u4e86\u590d\u5236\u5217\u8868\u521d\u59cb\u5316\u3002\u5217\u8868\u521d\u59cb\u5316\u7b80\u5355\u6765\u8bf4\u5c31\u662f\u7528\u82b1\u62ec\u53f7\u201c{}&#8221;\u53bb\u521d\u59cb\u5316\u4e00\u4e2a\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u9664\u4e86\u590d\u5236\u5217\u8868\u521d\u59cb\u5316\uff0c\u8fd8\u6709\u76f4\u63a5\u5217\u8868\u521d\u59cb\u5316\uff08<em>Direct-list-initialization<\/em>\uff09\u3002\u8fd9\u4e24\u4e2a\u6982\u5ff5\u987e\u540d\u601d\u4e49\uff0c\u76f4\u63a5\u5217\u8868\u521d\u59cb\u5316\u5c31\u662f\u76f4\u63a5\u7ed9\u5217\u8868\u7279\u5b9a\u7684\u503c\uff1b\u590d\u5236\u5217\u8868\u521d\u59cb\u5316\u4fa7\u91cd\u7684\u662f\u5c06\u4e00\u4e2a\u5df2\u6709\u5217\u8868\u7684\u503c\u53bb\u521d\u59cb\u5316\u53e6\u4e00\u4e2a\u5217\u8868\u3002\u76f8\u5f53\u4e8e\u201c\u65e0\u4e2d\u751f\u6709\u201d\u548c\u201c\u6709\u4e2d\u751f\u6709\u201d\u7684\u5bf9\u6bd4\u3002<\/p>\n\n\n\n<p>\u653e\u5b8c\u6574\u4ee3\u7801\u7684C++\u4ee3\u7801\u65b9\u4fbf\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>\u5b8c\u6574\u4ee3\u7801<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\n#include &lt;vector&gt;\nusing namespace std;\n\nvector&lt;int&gt;Return(vector&lt;int&gt;nums)\n{\n\tif (!nums.empty()&amp;&amp;nums.size()&gt;2)\n\t{\n\t\treturn {nums&#91;1],nums&#91;2]};\n\t}\n}\nvoid Show(vector&lt;int&gt;nums)\n{\n\tfor (int i = 0; i &lt; nums.size(); i++)\n\t{\n\t\tcout &lt;&lt; nums&#91;i]&lt;&lt;\" \";\n\t}\n\tcout &lt;&lt; endl;\n}\nint main()\n{\n\tvector&lt;int&gt;nums;\n\tfor (int i = 0; i &lt; 3; i++)\n\t{\n\t\tnums.push_back(i+1);\n\t}\n\tcout &lt;&lt; \"Vector Size=\" &lt;&lt; nums.size() &lt;&lt; endl;\n\tShow(nums);\n\tShow(Return(nums));\n}<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center\"><strong>\u8f93\u51fa\u793a\u4f8b<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"196\" height=\"100\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/09\/09a0fb9acf5f5e821eb56f644a79c37.png\" alt=\"\" class=\"wp-image-1894\" style=\"border-style:none;border-width:0px;border-radius:0px\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd4\u56de\u4e00\u4e2avector<\/p>\n","protected":false},"author":1,"featured_media":1894,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[84,33],"tags":[83,37],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/1882"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=1882"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/1882\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/1894"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=1882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=1882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=1882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}