Java simple solution beats 99.23%

  • 0

    A move is incrementing n - 1 elements by 1, can be regard as "a move is decrementing 1 element by 1. We can find the min element, calculate the sum of distance between it and other elements, and it is the min moves to get them equals others.

    public class Solution {
        public int minMoves(int[] nums) {
            int total = 0, min = nums[0];
            for (int i : nums){
                total += i;
                if (i < min) min = i;
            return total - min * nums.length;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.