<?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>symmetric Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/symmetric/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/symmetric/</link>
	<description></description>
	<lastBuildDate>Sat, 15 Dec 2018 09:18:03 +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>symmetric Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/symmetric/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 101. Symmetric Tree</title>
		<link>https://zxi.mytechroad.com/blog/tree/leetcode-101-symmetric-tree/</link>
					<comments>https://zxi.mytechroad.com/blog/tree/leetcode-101-symmetric-tree/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Fri, 27 Jul 2018 04:18:30 +0000</pubDate>
				<category><![CDATA[Tree]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[mirror]]></category>
		<category><![CDATA[recursion]]></category>
		<category><![CDATA[symmetric]]></category>
		<category><![CDATA[tree]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=3315</guid>

					<description><![CDATA[<p>Problem Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/tree/leetcode-101-symmetric-tree/">花花酱 LeetCode 101. Symmetric Tree</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>Problem</h1>
<p>Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).</p>
<p>For example, this binary tree <code>[1,2,2,3,4,4,3]</code> is symmetric:</p>
<pre class="crayon:false">    1
   / \
  2   2
 / \ / \
3  4 4  3
</pre>
<p>But the following <code>[1,2,2,null,3,null,3]</code> is not:</p>
<pre class="crayon:false ">    1
   / \
  2   2
   \   \
   3    3
</pre>
<p><b>Note:</b><br />
Bonus points if you could solve it both recursively and iteratively.</p>
<h1><strong>Solution: Recursion</strong></h1>
<p>Time complexity: O(n)</p>
<p>Space complexity: O(n)</p>
<p><div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">
</p><pre class="crayon-plain-tag">class Solution {
public:
  bool isSymmetric(TreeNode* root) {
    return isMirror(root, root);
  }
private:
  bool isMirror(TreeNode* root1, TreeNode* root2) {
    if (!root1 &amp;&amp; !root2) return true;
    if (!root1 || !root2) return false;
    return root1-&gt;val == root2-&gt;val 
           &amp;&amp; isMirror(root1-&gt;right, root2-&gt;left) 
           &amp;&amp; isMirror(root1-&gt;left, root2-&gt;right);
  }
};</pre><p></div><h2 class="tabtitle">Python</h2>
<div class="tabcontent">
</p><pre class="crayon-plain-tag">"""
Author: Huahua
Running time: 48 ms
"""
class Solution:
  def isSymmetric(self, root):
    def isMirror(root1, root2):
      if not root1 and not root2: return True
      if not root1 or not root2: return False
      return root1.val == root2.val \
        and isMirror(root1.left, root2.right) \
        and isMirror(root2.left, root1.right)
    return isMirror(root, root)</pre><p></div></div></p>
<h1><strong>Related Problems</strong></h1>
<ul>
<li><a href="http://zxi.mytechroad.com/blog/tree/leetcode-100-same-tree/">花花酱 Leetcode 100. Same Tree</a></li>
</ul>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/tree/leetcode-101-symmetric-tree/">花花酱 LeetCode 101. Symmetric Tree</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-101-symmetric-tree/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
