{"id":184,"date":"2013-10-01T12:37:47","date_gmt":"2013-10-01T04:37:47","guid":{"rendered":"http:\/\/cfan8.sinaapp.com\/?p=184"},"modified":"2013-10-01T12:37:47","modified_gmt":"2013-10-01T04:37:47","slug":"leetcode-populating-next-right-pointers-in-each-node-ii-%e5%b8%b8%e6%95%b0o1%e7%a9%ba%e9%97%b4%e8%a7%a3%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.linangran.com\/?p=184","title":{"rendered":"LeetCode: Populating Next Right Pointers in Each Node II constant O(1)\u7a7a\u95f4\u89e3\u6cd5"},"content":{"rendered":"<p>\u539f\u9898\u5730\u5740\u4e3a\uff1a<a href=\"http:\/\/oj.leetcode.com\/problems\/populating-next-right-pointers-in-each-node-ii\/\">http:\/\/oj.leetcode.com\/problems\/populating-next-right-pointers-in-each-node-ii\/<\/a><br \/>\n\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p>Follow up for problem &#8220;<em>Populating Next Right Pointers in Each Node<\/em>&#8220;.<\/p>\n<p>What if the given tree could be any binary tree? Would your previous solution still work?<\/p>\n<p><strong>Note:<\/strong><\/p>\n<ul>\n<li>You may only use constant extra space.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>For example,<br \/>\nGiven the following binary tree,<\/p>\n<pre>         1\n       \/  \n      2    3\n     \/     \n    4   5    7<\/pre>\n<p>&nbsp;<\/p>\n<p>After calling your function, the tree should look like:<\/p>\n<pre>         1 -&gt; NULL\n       \/  \n      2 -&gt; 3 -&gt; NULL\n     \/     \n    4-&gt; 5 -&gt; 7 -&gt; NULL<\/pre>\n<p>\u9898\u76ee\u7b80\u800c\u8a00\u4e4b\u5c31\u662f\u8981\u6309\u5c42\u904d\u5386\u4e8c\u53c9\u6811\uff0c\u7136\u540e\u52a0\u4e0a\u6307\u5411\u540c\u4e00\u5c42\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684\u5f15\u7528\u3002\u672c\u6765\u6ca1\u6709\u4ec0\u4e48\u96be\u5ea6\uff0c\u4f46\u662f\u9898\u76ee\u4e2d\u5e38\u6570\u7a7a\u95f4\u7684\u8981\u6c42\u628a\u8fd9\u9898\u7684\u505a\u6cd5\u9650\u5236\u7684\u6b7b\u6b7b\u7684\uff1a\u4e0d\u80fd\u989d\u5916\u5efa\u7acb\u4e00\u4e2a\u961f\u5217\uff0c\u4e0d\u80fd\u7528\u9012\u5f52\u3002<\/p>\n<p>\u8fd9\u4e2a\u9898\u76ee\u6700tricky\u7684\u5730\u65b9\u5c31\u662f\u5f53\u6211\u904d\u5386\u67d0\u4e00\u5c42\u7684\u65f6\u5019\uff0c\u5df2\u7ecf\u904d\u5386\u8fc7\u5e76\u5efa\u597d\u94fe\u8868\u7684\u4e0a\u4e00\u5c42\u672c\u8d28\u4e0a\u5c31\u662f\u4e00\u4e2a\u961f\u5217\uff01\u6211\u4eec\u53ea\u8981\u4fdd\u5b58\u597d\u5f53\u524d\u4e00\u5c42\u7684\u8d77\u70b9\uff0c\u5f53\u8fd9\u4e00\u5c42\u904d\u5386\u5b8c\u6210\u5f00\u59cb\u904d\u5386\u4e0b\u4e00\u5c42\u7684\u65f6\u5019\uff0c\u5229\u7528\u8fd9\u4e2a\u8d77\u70b9\u6784\u6210\u7684\u94fe\u8868\u8fdb\u884c\u6309\u5c42\u904d\u5386\u5373\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u9898\u5730\u5740\u4e3a\uff1ahttp:\/\/oj.leetcode.com\/problems\/populating-next-right-pointers-in-each-node-ii\/ \u5185\u5bb9\u5982\u4e0b\uff1a Follow up for problem &#8220;Populating Next Right Pointers in Each Node&#8220;. What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constant extra space. &nbsp; For example, Given the following binary tree, 1 \/ 2 3 \/ 4 5 7 &nbsp; After [&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":[11,24],"class_list":["post-184","post","type-post","status-publish","format-standard","hentry","category-study","tag-constant","tag-space"],"_links":{"self":[{"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/posts\/184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linangran.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184"}],"version-history":[{"count":0,"href":"https:\/\/www.linangran.com\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.linangran.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linangran.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linangran.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}