<?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>rectangle &#8211; Huahua&#8217;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/rectangle/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog</link>
	<description></description>
	<lastBuildDate>Sun, 05 Apr 2020 03:50:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>rectangle &#8211; Huahua&#8217;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1401. Circle and Rectangle Overlapping</title>
		<link>https://zxi.mytechroad.com/blog/geometry/leetcode-1401-circle-and-rectangle-overlapping/</link>
					<comments>https://zxi.mytechroad.com/blog/geometry/leetcode-1401-circle-and-rectangle-overlapping/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 05 Apr 2020 03:49:18 +0000</pubDate>
				<category><![CDATA[Geometry]]></category>
		<category><![CDATA[circle]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[inside]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[rectangle]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6569</guid>

					<description><![CDATA[Given a circle represented as (radius,&#160;x_center,&#160;y_center)&#160;and an axis-aligned rectangle represented as (x1,&#160;y1,&#160;x2,&#160;y2),&#160;where (x1,&#160;y1) are the coordinates of the bottom-left corner, and (x2,&#160;y2) are the coordinates&#8230;]]></description>
										<content:encoded><![CDATA[
<p>Given a circle represented as (<code>radius</code>,&nbsp;<code>x_center</code>,&nbsp;<code>y_center</code>)&nbsp;and an axis-aligned rectangle represented as (<code>x1</code>,&nbsp;<code>y1</code>,&nbsp;<code>x2</code>,&nbsp;<code>y2</code>),&nbsp;where (<code>x1</code>,&nbsp;<code>y1</code>) are the coordinates of the bottom-left corner, and (<code>x2</code>,&nbsp;<code>y2</code>) are the coordinates of the top-right corner of the&nbsp;rectangle.</p>



<p>Return True if the circle and rectangle are overlapped otherwise return False.</p>



<p>In other words, check if there are&nbsp;<strong>any&nbsp;</strong>point&nbsp;(xi, yi) such that belongs to the circle and the rectangle at the same time.</p>



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



<figure class="wp-block-image"><img decoding="async" src="https://assets.leetcode.com/uploads/2020/02/20/sample_4_1728.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> radius = 1, x_center = 0, y_center = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1
<strong>Output:</strong> true
<strong>Explanation:</strong> Circle and rectangle share the point (1,0) 
</pre>



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



<figure class="wp-block-image"><img decoding="async" src="https://assets.leetcode.com/uploads/2020/02/20/sample_2_1728.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> radius = 1, x_center = 0, y_center = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1
<strong>Output:</strong> true
</pre>



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



<figure class="wp-block-image"><img decoding="async" src="https://assets.leetcode.com/uploads/2020/03/03/sample_6_1728.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> radius = 1, x_center = 1, y_center = 1, x1 = -3, y1 = -3, x2 = 3, y2 = 3
<strong>Output:</strong> true
</pre>



<p><strong>Example 4:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> radius = 1, x_center = 1, y_center = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1
<strong>Output:</strong> false
</pre>



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



<ul class="wp-block-list"><li><code>1 &lt;= radius &lt;= 2000</code></li><li><code>-10^4 &lt;= x_center, y_center, x1, y1, x2, y2 &lt;= 10^4</code></li><li><code>x1 &lt; x2</code></li><li><code>y1 &lt; y2</code></li></ul>



<h2 class="wp-block-heading"><strong>Solution: Geometry</strong></h2>



<p>Find the shortest distance from the center to the rectangle, return dist &lt;= radius.</p>



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



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

<pre class="urvanov-syntax-highlighter-plain-tag">// Author: Huahua
class Solution {
public:
  bool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) {
    int dx = x_center - max(x1, min(x2, x_center));
    int dy = y_center - max(y1, min(y2, y_center));
    return dx * dx + dy * dy &lt;= radius * radius;
  }
};</pre>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/geometry/leetcode-1401-circle-and-rectangle-overlapping/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 85. Maximal Rectangle</title>
		<link>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-85-maximal-rectangle/</link>
					<comments>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-85-maximal-rectangle/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sat, 26 Jan 2019 18:21:08 +0000</pubDate>
				<category><![CDATA[Dynamic Programming]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[dp]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[hard]]></category>
		<category><![CDATA[rectangle]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4686</guid>

					<description><![CDATA[Given a 2D binary matrix filled with 0&#8217;s and 1&#8217;s, find the largest rectangle containing only 1&#8217;s and return its area. Example: Input: [ ["1","0","1","0","0"],&#8230;]]></description>
										<content:encoded><![CDATA[
<p>Given a 2D binary matrix filled with 0&#8217;s and 1&#8217;s, find the largest rectangle containing only 1&#8217;s and return its area.</p>



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



<pre class="wp-block-preformatted crayon:false"><strong>Input:</strong>
[
  ["1","0","1","0","0"],
  ["1","0","<strong>1</strong>","<strong>1</strong>","<strong>1</strong>"],
  ["1","1","<strong>1</strong>","<strong>1</strong>","<strong>1</strong>"],
  ["1","0","0","1","0"]
]
<strong>Output:</strong> 6</pre>



<h2 class="wp-block-heading">Solution: DP</h2>



<p>Time complexity: O(m^2*n)<br>Space complexity: O(mn)</p>



<p>dp[i][j] := max length of all 1 sequence ends with col j, at the i-th row.<br>transition: <br>dp[i][j] = 0 if matrix[i][j] == &#8216;0&#8217;<br>             = dp[i][j-1] + 1 if  matrix[i][j] == &#8216;1&#8217; </p>



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

<pre class="urvanov-syntax-highlighter-plain-tag">class Solution {
public:
  int maximalRectangle(vector&lt;vector&lt;char&gt; &gt; &amp;matrix) {
    int r = matrix.size();
    if (r == 0) return 0;
    int c = matrix[0].size();
  
    // dp[i][j] := max len of all 1s ends with col j at row i.
    vector&lt;vector&lt;int&gt;&gt; dp(r, vector&lt;int&gt;(c));

    for (int i = 0; i &lt; r; ++i)
      for (int j = 0; j &lt; c; ++j)
        dp[i][j] = (matrix[i][j] == '1') ? (j == 0 ? 1 : dp[i][j - 1] + 1) : 0;

    int ans = 0;

    for (int i = 0; i &lt; r; ++i)
      for (int j = 0; j &lt; c; ++j) {
        int len = INT_MAX;
        for (int k = i; k &lt; r; k++) {
          len = min(len, dp[k][j]);
          if (len == 0) break;
          ans = max(len * (k - i + 1), ans);
        }
    }

    return ans;
  }
};</pre>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-85-maximal-rectangle/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 963. Minimum Area Rectangle II</title>
		<link>https://zxi.mytechroad.com/blog/geometry/leetcode-963-minimum-area-rectangle-ii/</link>
					<comments>https://zxi.mytechroad.com/blog/geometry/leetcode-963-minimum-area-rectangle-ii/#comments</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Thu, 27 Dec 2018 05:40:35 +0000</pubDate>
				<category><![CDATA[Geometry]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[hashtable]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[rectangle]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4544</guid>

					<description><![CDATA[Given a set of points in the xy-plane, determine the minimum area of&#160;any&#160;rectangle formed from these points, with sides&#160;not necessarily parallel&#160;to the x and y&#8230;]]></description>
										<content:encoded><![CDATA[
<p>Given a set of points in the xy-plane, determine the minimum area of&nbsp;<strong>any</strong>&nbsp;rectangle formed from these points, with sides&nbsp;<strong>not necessarily parallel</strong>&nbsp;to the x and y axes.</p>



<p>If there isn&#8217;t any rectangle, return 0.</p>



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



<figure class="wp-block-image"><img decoding="async" src="https://assets.leetcode.com/uploads/2018/12/21/1a.png" alt=""/></figure>



<pre class="wp-block-preformatted crayon:false"><strong>Input: </strong>[[1,2],[2,1],[1,0],[0,1]]
<strong>Output: </strong>2.00000
<strong>Explanation:</strong> The minimum area rectangle occurs at [1,2],[2,1],[1,0],[0,1], with an area of 2.
</pre>



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



<figure class="wp-block-image"><img decoding="async" src="https://assets.leetcode.com/uploads/2018/12/22/2.png" alt=""/></figure>



<pre class="wp-block-preformatted crayon:false"><strong>Input: </strong>[[0,1],[2,1],[1,1],[1,0],[2,0]]
<strong>Output: </strong>1.00000
<strong>Explanation:</strong> The minimum area rectangle occurs at [1,0],[1,1],[2,1],[2,0], with an area of 1.
</pre>



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



<figure class="wp-block-image"><img decoding="async" src="https://assets.leetcode.com/uploads/2018/12/22/3.png" alt=""/></figure>



<pre class="wp-block-preformatted crayon:false"><strong>Input: </strong>[[0,3],[1,2],[3,1],[1,3],[2,1]]
<strong>Output: </strong>0
<strong>Explanation:</strong> There is no possible rectangle to form from these points.
</pre>



<p><strong>Example 4:</strong></p>



<figure class="wp-block-image"><img decoding="async" src="https://assets.leetcode.com/uploads/2018/12/21/4c.png" alt=""/></figure>



<pre class="wp-block-preformatted crayon:false"><strong>Input: </strong>[[3,1],[1,1],[0,1],[2,1],[3,3],[3,2],[0,2],[2,3]]
<strong>Output: </strong>2.00000
<strong>Explanation:</strong> The minimum area rectangle occurs at [2,1],[2,3],[3,3],[3,1], with an area of 2.
</pre>



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



<ol class="wp-block-list"><li><code>1 &lt;= points.length &lt;= 50</code></li><li><code>0 &lt;=&nbsp;points[i][0] &lt;=&nbsp;40000</code></li><li><code>0 &lt;=&nbsp;points[i][1] &lt;=&nbsp;40000</code></li><li>All points are distinct.</li><li>Answers within&nbsp;<code>10^-5</code>&nbsp;of the actual value will be accepted as correct.</li></ol>



<h1 class="wp-block-heading"><strong>Solution: HashTable</strong></h1>



<p>Iterate all possible triangles and check the opposite points that creating a quadrilateral. </p>



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



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

<pre class="urvanov-syntax-highlighter-plain-tag">class Solution {
public:
  double minAreaFreeRect(vector&lt;vector&lt;int&gt;&gt;&amp; points) {
    constexpr double INF_AREA = 1e100;
    const auto n = points.size();
    unordered_set&lt;int&gt; s;
    for (const auto&amp; p : points)
      s.insert(p[0] &lt;&lt; 16 | p[1]);
    double min_area = INF_AREA;
    for (int i = 0; i &lt; n; ++i)
      for (int j = 0; j &lt; n; ++j) {
        if (i == j) continue;
        for (int k = 0; k &lt; n; ++k) {
          if (i == k || j == k) continue;
          const auto&amp; p1 = points[i];
          const auto&amp; p2 = points[j];
          const auto&amp; p3 = points[k];
          int dot = (p2[0] - p1[0]) * (p3[0] - p1[0]) +
                    (p2[1] - p1[1]) * (p3[1] - p1[1]);
          if (dot != 0) continue;
          int p4_x = p2[0] + p3[0] - p1[0];
          int p4_y = p2[1] + p3[1] - p1[1];
          if (!s.count(p4_x &lt;&lt; 16 | p4_y)) continue;
          double a = pow(p2[0] - p1[0], 2) + pow(p2[1] - p1[1], 2);
          double b = pow(p3[0] - p1[0], 2) + pow(p3[1] - p1[1], 2);
          double area = a * b;
          min_area = min(min_area, area);
        }
      }
    return min_area &lt; INF_AREA ? sqrt(min_area) : 0;
  }
};</pre>
</div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/geometry/leetcode-963-minimum-area-rectangle-ii/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 939. Minimum Area Rectangle</title>
		<link>https://zxi.mytechroad.com/blog/geometry/leetcode-939-minimum-area-rectangle/</link>
					<comments>https://zxi.mytechroad.com/blog/geometry/leetcode-939-minimum-area-rectangle/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 11 Nov 2018 23:49:06 +0000</pubDate>
				<category><![CDATA[Geometry]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[hashtable]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[rectangle]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4297</guid>

					<description><![CDATA[Problem Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the&#8230;]]></description>
										<content:encoded><![CDATA[<h1><strong>Problem</strong></h1>
<p>Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these points, with sides parallel to the x and y axes.</p>
<p>If there isn&#8217;t any rectangle, return 0.</p>
<p><strong>Example 1:</strong></p>
<pre class="crayon:false"><strong>Input: </strong><span id="example-input-1-1">[[1,1],[1,3],[3,1],[3,3],[2,2]]</span>
<strong>Output: </strong><span id="example-output-1">4</span>
</pre>
<p><strong>Example 2:</strong></p>
<pre class="crayon:false"><strong>Input: </strong><span id="example-input-2-1">[[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]</span>
<strong>Output: </strong><span id="example-output-2">2</span>
</pre>
<p><strong>Note</strong>:</p>
<ol>
<li><code>1 &lt;= points.length &lt;= 500</code></li>
<li><code>0 &lt;= points[i][0] &lt;= 40000</code></li>
<li><code>0 &lt;= points[i][1] &lt;= 40000</code></li>
<li>All points are distinct.</li>
</ol>
<h1>Solution 1: HashTable + Brute Force</h1>
<p>Try all pairs of points to form a diagonal and see whether pointers of another diagonal exist or not.</p>
<p>Assume two points are (x0, y0), (x1, y1) x0 != x1 and y0 != y1. The other two points will be (x0, y1), (x1, y0)</p>
<p>Time complexity: O(n^2)</p>
<p>Space complexity: O(n)</p>
<p><div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">
</p><pre class="urvanov-syntax-highlighter-plain-tag">// Author: Huahua, running time: 96 ms
class Solution {
public:
  int minAreaRect(vector&lt;vector&lt;int&gt;&gt;&amp; points) {    
    unordered_map&lt;int, unordered_set&lt;int&gt;&gt; s;
    for (const auto&amp; point : points)
      s[point[0]].insert(point[1]);
    
    const int n = points.size();
    int min_area = INT_MAX;
    for (int i = 0; i &lt; n; ++i)
      for (int j = i + 1; j &lt; n; ++j) {
        int x0 = points[i][0];
        int y0 = points[i][1];
        int x1 = points[j][0];
        int y1 = points[j][1];
        if (x0 == x1 || y0 == y1) continue;
        int area = abs(x0 - x1) * abs(y0 - y1);
        if (area &gt; min_area) continue;
        if (!s[x1].count(y0) || !s[x0].count(y1)) continue;
        min_area = area;
      }
    return min_area == INT_MAX ? 0 : min_area;
  }
};</pre><p></div><h2 class="tabtitle">C++ / 1D hashtable</h2>
<div class="tabcontent">
</p><pre class="urvanov-syntax-highlighter-plain-tag">// Author: Huahua, 68 ms
class Solution {
public:
  int minAreaRect(vector&lt;vector&lt;int&gt;&gt;&amp; points) {    
    unordered_set&lt;int&gt; s;
    for (const auto&amp; point : points)
      s.insert((point[0] &lt;&lt; 16) | point[1]);
    
    const int n = points.size();
    int min_area = INT_MAX;
    for (int i = 0; i &lt; n; ++i)
      for (int j = i + 1; j &lt; n; ++j) {
        int x0 = points[i][0];
        int y0 = points[i][1];
        int x1 = points[j][0];
        int y1 = points[j][1];
        if (x0 == x1 || y0 == y1) continue;
        int area = abs(x0 - x1) * abs(y0 - y1);
        if (area &gt; min_area) continue;
        int p0 = (x1 &lt;&lt; 16) | y0;
        int p1 = (x0 &lt;&lt; 16) | y1;
        if (!s.count(p0) || !s.count(p1)) continue;
        min_area = area;
      }
    return min_area == INT_MAX ? 0 : min_area;
  }
};</pre><p></div></div></p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/geometry/leetcode-939-minimum-area-rectangle/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 223. Rectangle Area</title>
		<link>https://zxi.mytechroad.com/blog/geometry/leetcode-223-rectangle-area/</link>
					<comments>https://zxi.mytechroad.com/blog/geometry/leetcode-223-rectangle-area/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Wed, 19 Sep 2018 07:24:55 +0000</pubDate>
				<category><![CDATA[Geometry]]></category>
		<category><![CDATA[area]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[rectangle]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4032</guid>

					<description><![CDATA[Problem Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown&#8230;]]></description>
										<content:encoded><![CDATA[<h1><strong>Problem</strong></h1>
<p>Find the total area covered by two <strong>rectilinear</strong> rectangles in a <strong>2D</strong> plane.</p>
<p>Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.</p>
<p><img decoding="async" src="https://leetcode.com/static/images/problemset/rectangle_area.png" alt="Rectangle Area" /></p>
<p><strong>Example:</strong></p>
<pre class="crayon:false "><strong>Input: </strong>A = <span id="example-input-1-1">-3</span>, B = <span id="example-input-1-2">0</span>, C = <span id="example-input-1-3">3</span>, D = <span id="example-input-1-4">4</span>, E = <span id="example-input-1-5">0</span>, F = <span id="example-input-1-6">-1</span>, G = <span id="example-input-1-7">9</span>, H = <span id="example-input-1-8">2</span>
<strong>Output: </strong><span id="example-output-1">45</span></pre>
<p><strong>Note:</strong></p>
<p>Assume that the total area is never beyond the maximum possible value of <strong>int</strong>.</p>
<h1>Solution:</h1>
<p>area1 + area2 &#8211; overlapped area</p>
<p>Time complexity: O(1)</p>
<p>Space complexity: O(1)</p>
<p><div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">
</p><pre class="urvanov-syntax-highlighter-plain-tag">// Author: Huahua
class Solution {
public:
  int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
    int area1 = (C - A) * (D - B);
    int area2 = (G - E) * (H - F);
    int x1 = max(A, E);
    int x2 = max(x1, min(C, G));
    int y1 = max(B, F);
    int y2 = max(y1, min(D, H));
    return area1 + area2 - (x2 - x1) * (y2 - y1);
  }
};</pre><p></div><h2 class="tabtitle">Java</h2>
<div class="tabcontent">
</p><pre class="urvanov-syntax-highlighter-plain-tag">// Author: Huahua
class Solution {
  public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
    int area1 = (C - A) * (D - B);
    int area2 = (G - E) * (H - F);
    int x1 = Math.max(A, E);
    int x2 = Math.max(x1, Math.min(C, G));
    int y1 = Math.max(B, F);
    int y2 = Math.max(y1, Math.min(D, H));
    return area1 + area2 - (x2 - x1) * (y2 - y1);
  }
}</pre><p></div><h2 class="tabtitle">Python3</h2>
<div class="tabcontent">
</p><pre class="urvanov-syntax-highlighter-plain-tag"># Author: Huahua
class Solution:
  def computeArea(self, A, B, C, D, E, F, G, H):
    area1 = (C - A) * (D - B);
    area2 = (G - E) * (H - F);
    x1 = max(A, E);
    x2 = max(x1, min(C, G));
    y1 = max(B, F);
    y2 = max(y1, min(D, H));
    return area1 + area2 - (x2 - x1) * (y2 - y1)</pre><p></div></div></p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/geometry/leetcode-223-rectangle-area/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 836. Rectangle Overlap</title>
		<link>https://zxi.mytechroad.com/blog/geometry/leetcode-836-rectangle-overlap/</link>
					<comments>https://zxi.mytechroad.com/blog/geometry/leetcode-836-rectangle-overlap/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Thu, 19 Jul 2018 16:23:43 +0000</pubDate>
				<category><![CDATA[Geometry]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[overlap]]></category>
		<category><![CDATA[rectangle]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=3223</guid>

					<description><![CDATA[Problem A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bottom-left corner, and (x2, y2) are the coordinates of its top-right corner. Two&#8230;]]></description>
										<content:encoded><![CDATA[<h1><strong>Problem</strong></h1>
<p>A rectangle is represented as a list <code>[x1, y1, x2, y2]</code>, where <code>(x1, y1)</code> are the coordinates of its bottom-left corner, and <code>(x2, y2)</code> are the coordinates of its top-right corner.</p>
<p>Two rectangles overlap if the area of their intersection is positive.  To be clear, two rectangles that only touch at the corner or edges do not overlap.</p>
<p>Given two (axis-aligned) rectangles, return whether they overlap.</p>
<p><strong>Example 1:</strong></p>
<pre class="crayon:false"><strong>Input: </strong>rec1 = [0,0,2,2], rec2 = [1,1,3,3]
<strong>Output: </strong>true
</pre>
<p><strong>Example 2:</strong></p>
<pre class="crayon:false "><strong>Input: </strong>rec1 = [0,0,1,1], rec2 = [1,0,2,1]
<strong>Output: </strong>false
</pre>
<p><strong>Notes:</strong></p>
<ol>
<li>Both rectangles <code>rec1</code> and <code>rec2</code> are lists of 4 integers.</li>
<li>All coordinates in rectangles will be between <code>-10^9 </code>and<code> 10^9</code>.</li>
</ol>
<h1><strong>Solution: Geometry</strong></h1>
<p>Time complexity: O(1)</p>
<p>Space complexity: O(1)</p><pre class="urvanov-syntax-highlighter-plain-tag">// Author: Huahua
// Running time: 0 ms
class Solution {
public:
  bool isRectangleOverlap(vector&lt;int&gt;&amp; rec1, vector&lt;int&gt;&amp; rec2) {
    return rec1[0] &lt; rec2[2] &amp;&amp; rec2[0] &lt; rec1[2] &amp;&amp;
           rec1[1] &lt; rec2[3] &amp;&amp; rec2[1] &lt; rec1[3];
  }
};</pre><p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/geometry/leetcode-836-rectangle-overlap/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
