<?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>inplace Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/inplace/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/inplace/</link>
	<description></description>
	<lastBuildDate>Mon, 09 Aug 2021 03:22:56 +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>inplace Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/inplace/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1886. Determine Whether Matrix Can Be Obtained By Rotation</title>
		<link>https://zxi.mytechroad.com/blog/simulation/leetcode-1886-determine-whether-matrix-can-be-obtained-by-rotation/</link>
					<comments>https://zxi.mytechroad.com/blog/simulation/leetcode-1886-determine-whether-matrix-can-be-obtained-by-rotation/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 09 Aug 2021 03:22:13 +0000</pubDate>
				<category><![CDATA[Simulation]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[inplace]]></category>
		<category><![CDATA[matrix]]></category>
		<category><![CDATA[rotation]]></category>
		<category><![CDATA[simulation]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=8537</guid>

					<description><![CDATA[<p>Given two&#160;n x n&#160;binary matrices&#160;mat&#160;and&#160;target, return&#160;true&#160;if it is possible to make&#160;mat&#160;equal to&#160;target&#160;by&#160;rotating&#160;mat&#160;in&#160;90-degree increments, or&#160;false&#160;otherwise. Example 1: Input: mat = [[0,1],[1,0]], target = [[1,0],[0,1]] Output: true&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-1886-determine-whether-matrix-can-be-obtained-by-rotation/">花花酱 LeetCode 1886. Determine Whether Matrix Can Be Obtained By Rotation</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 two&nbsp;<code>n x n</code>&nbsp;binary matrices&nbsp;<code>mat</code>&nbsp;and&nbsp;<code>target</code>, return&nbsp;<code>true</code><em>&nbsp;if it is possible to make&nbsp;</em><code>mat</code><em>&nbsp;equal to&nbsp;</em><code>target</code><em>&nbsp;by&nbsp;<strong>rotating</strong>&nbsp;</em><code>mat</code><em>&nbsp;in&nbsp;<strong>90-degree increments</strong>, or&nbsp;</em><code>false</code><em>&nbsp;otherwise.</em></p>



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



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2021/05/20/grid3.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> mat = [[0,1],[1,0]], target = [[1,0],[0,1]]
<strong>Output:</strong> true
<strong>Explanation: </strong>We can rotate mat 90 degrees clockwise to make mat equal target.
</pre>



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



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2021/05/20/grid4.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> mat = [[0,1],[1,1]], target = [[1,0],[0,1]]
<strong>Output:</strong> false
<strong>Explanation:</strong> It is impossible to make mat equal to target by rotating mat.
</pre>



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



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2021/05/26/grid4.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]
<strong>Output:</strong> true
<strong>Explanation: </strong>We can rotate mat 90 degrees clockwise two times to make mat equal target.
</pre>



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



<ul><li><code>n == mat.length == target.length</code></li><li><code>n == mat[i].length == target[i].length</code></li><li><code>1 &lt;= n &lt;= 10</code></li><li><code>mat[i][j]</code>&nbsp;and&nbsp;<code>target[i][j]</code>&nbsp;are either&nbsp;<code>0</code>&nbsp;or&nbsp;<code>1</code>.</li></ul>



<h2><strong>Solution: Simulation</strong></h2>



<p>Time complexity: O(n<sup>2</sup>)<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:
  bool findRotation(vector&lt;vector&lt;int&gt;&gt;&amp; mat, vector&lt;vector&lt;int&gt;&gt;&amp; target) {    
    const int n = mat.size();
    auto rot = [n](vector&lt;vector&lt;int&gt;&gt;&amp; mat) {      
      for (int i = 0; i &lt; n; ++i)
        for (int j = i; j &lt; n; ++j)
          swap(mat[i][j], mat[j][i]);
      for (int j = 0; j &lt; n; j++)
        for (int i = 0; i &lt; n / 2; ++i)
          swap(mat[i][j], mat[n - i - 1][j]);
      return mat;
    };
    for (int i = 0; i &lt; 4; ++i)
      if (rot(mat) == target) return true;    
    return false;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-1886-determine-whether-matrix-can-be-obtained-by-rotation/">花花酱 LeetCode 1886. Determine Whether Matrix Can Be Obtained By Rotation</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/simulation/leetcode-1886-determine-whether-matrix-can-be-obtained-by-rotation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
