mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
23 lines
1.5 KiB
HTML
23 lines
1.5 KiB
HTML
<p>Given two squares on a two-dimensional plane, find a line that would cut these two squares in half. Assume that the top and the bottom sides of the square run parallel to the x-axis.</p>
|
|
|
|
|
|
|
|
<p>Each square consists of three values, the coordinate of bottom left corner <code>[X,Y] = [square[0],square[1]]</code>, and the side length of the square <code>square[2]</code>. The line will intersect to the two squares in four points. Return the coordinates of two intersection points <code>[X<sub>1</sub>,Y<sub>1</sub>]</code> and <code>[X<sub>2</sub>,Y<sub>2</sub>]</code> that the forming segment covers the other two intersection points in format of <code>{X<sub>1</sub>,Y<sub>1</sub>,X<sub>2</sub>,Y<sub>2</sub>}</code>. If <code>X<sub>1</sub> != X<sub>2</sub></code>, there should be <code>X<sub>1</sub> < X<sub>2</sub></code>, otherwise there should be <code>Y<sub>1</sub> <= Y<sub>2</sub></code>.</p>
|
|
|
|
|
|
|
|
<p>If there are more than one line that can cut these two squares in half, return the one that has biggest slope (slope of a line parallel to the y-axis is considered as infinity).</p>
|
|
|
|
|
|
|
|
<p><strong>Example: </strong></p>
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
<strong>Input: </strong>
|
|
|
|
square1 = {-1, -1, 2}
|
|
|
|
square2 = {0, -1, 2}
|
|
|
|
<strong>Output:</strong> {-1,0,2,0}
|
|
|
|
<strong>Explanation:</strong> y = 0 is the line that can cut these two squares in half.
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p><strong>Note: </strong></p>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li><code>square.length == 3</code></li>
|
|
|
|
<li><code>square[2] > 0</code></li>
|
|
|
|
</ul>
|
|
|