Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 930 Bytes

0453-minimum-moves-to-equal-array-elements.adoc

File metadata and controls

32 lines (22 loc) · 930 Bytes

453. Minimum Moves to Equal Array Elements

{leetcode}/problems/minimum-moves-to-equal-array-elements/[LeetCode - Minimum Moves to Equal Array Elements^]

Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.

Example:

Input:
[1,2,3]

Output:
3

Explanation:
Only three moves are needed (remember each move increments two elements):

[1,2,3]  =>  [2,3,3]  =>  [3,4,3]  =>  [4,4,4]

题解

题目说明,每次给 n - 1 个元素加 1,反过来就是给一个元素减 1,这样只需要把所有数减到数组最小值即可,也就是所有数和最小值的差值之和。

link:{sourcedir}/_0453_MinimumMovesToEqualArrayElements.java[role=include]