Skip to main content
Back to problems
#453
Medium Algorithms

Minimum moves to equal array elements

Array Math
58.5% acceptance
Jan 13, 2026
2813
1914
Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal. In one move, you can increment n - 1 elements of the array by 1.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn min_moves(nums: Vec<i32>) -> i32 {
    let min = *nums.iter().min().unwrap();
    nums.iter().map(|&n| n - min).sum()
  }
}