<?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>mirror Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/mirror/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/mirror/</link>
	<description></description>
	<lastBuildDate>Wed, 02 Oct 2019 16:21:29 +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>mirror Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/mirror/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 48. Rotate Image</title>
		<link>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-48-rotate-image/</link>
					<comments>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-48-rotate-image/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Wed, 02 Oct 2019 16:20:55 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[flip]]></category>
		<category><![CDATA[in place]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[mirror]]></category>
		<category><![CDATA[O(n^2)]]></category>
		<category><![CDATA[rotate]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5698</guid>

					<description><![CDATA[<p>You are given an&#160;n&#160;x&#160;n&#160;2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image&#160;in-place, which means you&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/algorithms/array/leetcode-48-rotate-image/">花花酱 LeetCode 48. Rotate Image</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>You are given an&nbsp;<em>n</em>&nbsp;x&nbsp;<em>n</em>&nbsp;2D matrix representing an image.</p>



<p>Rotate the image by 90 degrees (clockwise).</p>



<p><strong>Note:</strong></p>



<p>You have to rotate the image&nbsp;<a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank" rel="noreferrer noopener"><strong>in-place</strong></a>, which means you have to modify the input 2D matrix directly.&nbsp;<strong>DO NOT</strong>&nbsp;allocate another 2D matrix and do the rotation.</p>



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



<pre class="wp-block-preformatted;crayon:false">Given <strong>input matrix</strong> = 
[
  [1,2,3],
  [4,5,6],
  [7,8,9]
],

rotate the input matrix <strong>in-place</strong> such that it becomes:
[
  [7,4,1],
  [8,5,2],
  [9,6,3]
]
</pre>



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



<pre class="wp-block-preformatted;crayon:false">Given <strong>input matrix</strong> =
[
  [ 5, 1, 9,11],
  [ 2, 4, 8,10],
  [13, 3, 6, 7],
  [15,14,12,16]
], 

rotate the input matrix <strong>in-place</strong> such that it becomes:
[
  [15,13, 2, 5],
  [14, 3, 4, 1],
  [12, 6, 8, 9],
  [16, 7,10,11]
]</pre>



<h2><strong>Solution: 2 Passes</strong></h2>



<p>First pass: mirror around diagonal <br>Second pass: mirror around y axis</p>



<p>Time complexity: O(n^2)<br>Space complexity: O(1)</p>



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

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  void rotate(vector&lt;vector&lt;int&gt;&gt;&amp; matrix) {
    const int n = matrix.size();
    for (int i = 0; i &lt; n; ++i)
      for (int j = i + 1; j &lt; n; ++j)
        swap(matrix[i][j], matrix[j][i]);
    for (int i = 0; i &lt; n; ++i)
      reverse(begin(matrix[i]), end(matrix[i]));
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/algorithms/array/leetcode-48-rotate-image/">花花酱 LeetCode 48. Rotate Image</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/algorithms/array/leetcode-48-rotate-image/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<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>
