155ms brute force solution

  • 0
    public class Solution {
        public int minMoves(int[] nums) {
            int sum = 0;
            for(int i=nums.length-1;i>0;i--){
                int diff = nums[i] -nums[0];
                sum += diff;
                for(int j=i-1;j>=0;j--)
                    nums[j] += diff;
            return sum;

Log in to reply

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