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)/最小操作次数使数组元素相等 [minimum-moves-to-equal-array-elements].html
2022-03-29 12:43:11 +08:00

32 lines
907 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>n - 1</code> 个元素增加 <code>1</code> 。返回让数组所有元素相等的最小操作次数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,3]
<strong>输出:</strong>3
<strong>解释:</strong>
只需要3次操作注意每次操作会增加两个元素的值
[1,2,3] =&gt; [2,3,3] =&gt; [3,4,3] =&gt; [4,4,4]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,1,1]
<strong>输出:</strong>0
</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>
<li>答案保证符合 <strong>32-bit</strong> 整数</li>
</ul>