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)/最小操作次数使数组元素相等 II [minimum-moves-to-equal-array-elements-ii].html
2023-12-09 18:53:53 +08:00

33 lines
951 B
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>n</code> 的整数数组 <code>nums</code> ,返回使所有数组元素相等需要的最小操作数。</p>
<p>在一次操作中,你可以使数组中的一个元素加 <code>1</code> 或者减 <code>1</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,3]
<strong>输出:</strong>2
<strong>解释:</strong>
只需要两次操作(每次操作指南使一个元素加 1 或减 1
[<strong><em>1</em></strong>,2,3] =&gt; [2,2,<strong><em>3</em></strong>] =&gt; [2,2,2]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,10,2,9]
<strong>输出:</strong>16
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>