<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>pre-order Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/pre-order/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/pre-order/</link>
	<description></description>
	<lastBuildDate>Mon, 29 Nov 2021 03:43:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>pre-order Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/pre-order/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 199. Binary Tree Right Side View</title>
		<link>https://zxi.mytechroad.com/blog/tree/leetcode-199-binary-tree-right-side-view/</link>
					<comments>https://zxi.mytechroad.com/blog/tree/leetcode-199-binary-tree-right-side-view/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 29 Nov 2021 03:43:18 +0000</pubDate>
				<category><![CDATA[Tree]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[level]]></category>
		<category><![CDATA[pre-order]]></category>
		<category><![CDATA[tree]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=8894</guid>

					<description><![CDATA[<p>Given the&#160;root&#160;of a binary tree, imagine yourself standing on the&#160;right side&#160;of it, return&#160;the values of the nodes you can see ordered from top to bottom.&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/tree/leetcode-199-binary-tree-right-side-view/">花花酱 LeetCode 199. Binary Tree Right Side View</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Given the&nbsp;<code>root</code>&nbsp;of a binary tree, imagine yourself standing on the&nbsp;<strong>right side</strong>&nbsp;of it, return&nbsp;<em>the values of the nodes you can see ordered from top to bottom</em>.</p>



<p><strong>Example 1:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2021/02/14/tree.jpg" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> root = [1,2,3,null,5,null,4]
<strong>Output:</strong> [1,3,4]
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> root = [1,null,3]
<strong>Output:</strong> [1,3]
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> root = []
<strong>Output:</strong> []
</pre>



<p><strong>Constraints:</strong></p>



<ul><li>The number of nodes in the tree is in the range&nbsp;<code>[0, 100]</code>.</li><li><code>-100 &lt;= Node.val &lt;= 100</code></li></ul>



<h2><strong>Solution: Pre-order traversal</strong></h2>



<p>By using pre-order traversal, the right most node will be the last one to visit in each level.</p>



<p>Time complexity: O(n)<br>Space complexity: O(|height|)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;int&gt; rightSideView(TreeNode* root) {
    vector&lt;int&gt; ans;
    function&lt;void(TreeNode*, int)&gt; dfs = [&amp;](TreeNode* root, int d) {
      if (!root) return;
      if (ans.size() &lt; d + 1) ans.push_back(0);
      ans[d] = root-&gt;val;
      dfs(root-&gt;left, d + 1);
      dfs(root-&gt;right, d + 1);
    };
    dfs(root, 0);
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/tree/leetcode-199-binary-tree-right-side-view/">花花酱 LeetCode 199. Binary Tree Right Side View</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/tree/leetcode-199-binary-tree-right-side-view/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
