1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/交点 [intersection-lcci].html
2022-03-29 12:43:11 +08:00

39 lines
1.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定两条线段(表示为起点<code>start = {X1, Y1}</code>和终点<code>end = {X2, Y2}</code>),如果它们有交点,请计算其交点,没有交点则返回空值。</p>
<p>要求浮点型误差不超过<code>10^-6</code>。若有多个交点(线段重叠)则返回 X 值最小的点X 坐标相同则返回 Y 值最小的点。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>
line1 = {0, 0}, {1, 0}
line2 = {1, 1}, {0, -1}
<strong>输出:</strong> {0.5, 0}
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>
line1 = {0, 0}, {3, 3}
line2 = {1, 1}, {2, 2}
<strong>输出:</strong> {1, 1}
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>
line1 = {0, 0}, {1, 1}
line2 = {1, 0}, {2, 1}
<strong>输出:</strong> {},两条线段没有交点
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>坐标绝对值不会超过 2^7</li>
<li>输入的坐标均是有效的二维坐标</li>
</ul>