453. Minimum Moves to Equal Array Elements Medium

@problem@discussion
#Array#Math



1/**
2 * [453] Minimum Moves to Equal Array Elements
3 *
4 * Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.
5 * In one move, you can increment n - 1 elements of the array by 1.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [1,2,3]
10 * Output: 3
11 * Explanation: Only three moves are needed (remember each move increments two elements):
12 * [1,2,3]  =>  [2,3,3]  =>  [3,4,3]  =>  [4,4,4]
13 * 
14 * Example 2:
15 * 
16 * Input: nums = [1,1,1]
17 * Output: 0
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	n == nums.length
23 * 	1 <= nums.length <= 10^5
24 * 	-10^9 <= nums[i] <= 10^9
25 * 	The answer is guaranteed to fit in a 32-bit integer.
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/minimum-moves-to-equal-array-elements/
31// discuss: https://leetcode.com/problems/minimum-moves-to-equal-array-elements/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn min_moves(nums: Vec<i32>) -> i32 {
37        0
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_453() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.