1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/两球之间的磁力 [magnetic-force-between-two-balls].html
2022-03-29 12:43:11 +08:00

36 lines
1.8 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>在代号为 C-137 的地球上Rick 发现如果他将两个球放在他新发明的篮子里它们之间会形成特殊形式的磁力。Rick 有&nbsp;<code>n</code>&nbsp;个空的篮子,第&nbsp;<code>i</code>&nbsp;个篮子的位置在&nbsp;<code>position[i]</code>&nbsp;Morty&nbsp;想把&nbsp;<code>m</code>&nbsp;个球放到这些篮子里,使得任意两球间&nbsp;<strong>最小磁力</strong>&nbsp;最大。</p>
<p>已知两个球如果分别位于&nbsp;<code>x</code>&nbsp;&nbsp;<code>y</code>&nbsp;,那么它们之间的磁力为&nbsp;<code>|x - y|</code>&nbsp;</p>
<p>给你一个整数数组&nbsp;<code>position</code>&nbsp;和一个整数&nbsp;<code>m</code>&nbsp;,请你返回最大化的最小磁力。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/08/16/q3v1.jpg" style="height: 195px; width: 562px;"></p>
<pre><strong>输入:</strong>position = [1,2,3,4,7], m = 3
<strong>输出:</strong>3
<strong>解释:</strong>将 3 个球分别放入位于 14 和 7 的三个篮子,两球间的磁力分别为 [3, 3, 6]。最小磁力为 3 。我们没办法让最小磁力大于 3 。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>position = [5,4,3,2,1,1000000000], m = 2
<strong>输出:</strong>999999999
<strong>解释:</strong>我们使用位于 1 和 1000000000 的篮子时最小磁力最大。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == position.length</code></li>
<li><code>2 &lt;= n &lt;= 10^5</code></li>
<li><code>1 &lt;= position[i] &lt;= 10^9</code></li>
<li>所有&nbsp;<code>position</code>&nbsp;中的整数 <strong>互不相同</strong>&nbsp;</li>
<li><code>2 &lt;= m &lt;= position.length</code></li>
</ul>