{"id":2024,"date":"2016-05-17T20:48:30","date_gmt":"2016-05-17T12:48:30","guid":{"rendered":"http:\/\/boweihe.me\/?p=2024"},"modified":"2016-05-17T20:48:30","modified_gmt":"2016-05-17T12:48:30","slug":"leetcode-119-pascals-triangle-ii","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=2024","title":{"rendered":"LeetCode 119. Pascal&#039;s Triangle II"},"content":{"rendered":"<h3>\u9898\u76ee<\/h3>\n<p>Given an index <i>k<\/i>, return the <i>k<\/i><sup>th<\/sup> row of the Pascal&#8217;s triangle.<br \/>\nFor example, given <i>k<\/i> = 3,<br \/>\nReturn <code>[1,3,3,1]<\/code>.<br \/>\n<b>Note:<\/b><br \/>\nCould you optimize your algorithm to use only <i>O<\/i>(<i>k<\/i>) extra space?<\/p>\n<h3>\u601d\u8def<\/h3>\n<p>\u4ea4\u66ff\u4f7f\u7528\u4e24\u4e2a\u6570\u7ec4\u5373\u53ef\u3002<\/p>\n<h3>\u4ee3\u7801<\/h3>\n<pre class=\"lang:c++ decode:true \">class Solution {\npublic:\n    vector&lt;int&gt; getRow(int rowIndex) {\n        rowIndex++;\n        if(rowIndex &lt; 1){\n            return vector&lt;int&gt;();\n        }\n        vector&lt;int&gt; temp0(rowIndex, 0);\n        vector&lt;int&gt; temp1(rowIndex, 0);\n        vector&lt;int&gt;* pCurrRow = &amp;temp0;\n        vector&lt;int&gt;* pLastRow = &amp;temp1;\n        for(int i=0; i&lt;rowIndex; i++){\n            (*pCurrRow)[0] = 1;\n            for(int col=1; col&lt;=i; col++){\n                (*pCurrRow)[col] = (*pLastRow)[col-1] + (*pLastRow)[col];\n            }\n            vector&lt;int&gt;* pTemp = pLastRow;\n            pLastRow = pCurrRow;\n            pCurrRow = pTemp;\n        }\n        return (*pLastRow);\n    }\n};<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee Given an index k, return the kth row of the Pascal&#8217;s triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? \u601d\u8def \u4ea4\u66ff\u4f7f\u7528\u4e24\u4e2a\u6570\u7ec4\u5373\u53ef\u3002 \u4ee3\u7801 class Solution { public: vector&lt;int&gt; getRow(int rowIndex) { rowIndex++; if(rowIndex &lt; 1){ return vector&lt;int&gt;(); } vector&lt;int&gt; temp0(rowIndex, 0); vector&lt;int&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[66,165],"class_list":["post-2024","post","type-post","status-publish","format-standard","hentry","category-study","tag-leetcode-oj","tag-165"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/2024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2024"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/2024\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}