{"id":3223,"date":"2018-07-19T09:23:43","date_gmt":"2018-07-19T16:23:43","guid":{"rendered":"http:\/\/zxi.mytechroad.com\/blog\/?p=3223"},"modified":"2018-07-19T09:23:58","modified_gmt":"2018-07-19T16:23:58","slug":"leetcode-836-rectangle-overlap","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/geometry\/leetcode-836-rectangle-overlap\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 836. Rectangle Overlap"},"content":{"rendered":"<h1><strong>Problem<\/strong><\/h1>\n<p>A rectangle is\u00a0represented as a\u00a0list\u00a0<code>[x1, y1, x2, y2]<\/code>, where\u00a0<code>(x1, y1)<\/code>\u00a0are the coordinates of its bottom-left corner, and\u00a0<code>(x2,\u00a0y2)<\/code>\u00a0are the coordinates of its top-right corner.<\/p>\n<p>Two rectangles overlap if the area of their intersection is positive.\u00a0 To be clear, two rectangles that only touch at the corner or edges do not overlap.<\/p>\n<p>Given two (axis-aligned) rectangles, return whether\u00a0they overlap.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre class=\"crayon:false\"><strong>Input: <\/strong>rec1 = [0,0,2,2], rec2 = [1,1,3,3]\r\n<strong>Output: <\/strong>true\r\n<\/pre>\n<p><strong>Example 2:<\/strong><\/p>\n<pre class=\"crayon:false \"><strong>Input: <\/strong>rec1 = [0,0,1,1], rec2 = [1,0,2,1]\r\n<strong>Output: <\/strong>false\r\n<\/pre>\n<p><strong>Notes:<\/strong><\/p>\n<ol>\n<li>Both rectangles\u00a0<code>rec1<\/code>\u00a0and\u00a0<code>rec2<\/code>\u00a0are lists of 4 integers.<\/li>\n<li>All coordinates in rectangles will be between\u00a0<code>-10^9\u00a0<\/code>and<code>\u00a010^9<\/code>.<\/li>\n<\/ol>\n<h1><strong>Solution: Geometry<\/strong><\/h1>\n<p>Time complexity: O(1)<\/p>\n<p>Space complexity: O(1)<\/p>\n<pre class=\"lang:default decode:true \">\/\/ Author: Huahua\r\n\/\/ Running time: 0 ms\r\nclass Solution {\r\npublic:\r\n  bool isRectangleOverlap(vector&lt;int&gt;&amp; rec1, vector&lt;int&gt;&amp; rec2) {\r\n    return rec1[0] &lt; rec2[2] &amp;&amp; rec2[0] &lt; rec1[2] &amp;&amp;\r\n           rec1[1] &lt; rec2[3] &amp;&amp; rec2[1] &lt; rec1[3];\r\n  }\r\n};<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem A rectangle is\u00a0represented as a\u00a0list\u00a0[x1, y1, x2, y2], where\u00a0(x1, y1)\u00a0are the coordinates of its bottom-left corner, and\u00a0(x2,\u00a0y2)\u00a0are the coordinates of its top-right corner. Two&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127],"tags":[222,284,159,343],"class_list":["post-3223","post","type-post","status-publish","format-standard","hentry","category-geometry","tag-easy","tag-geometry","tag-overlap","tag-rectangle","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/3223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=3223"}],"version-history":[{"count":2,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/3223\/revisions"}],"predecessor-version":[{"id":3225,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/3223\/revisions\/3225"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=3223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=3223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=3223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}