C simply solution, 33ms


  • 2
    L
    int minMoves(int* nums, int numsSize) {
        
        int minNum=nums[0];
        int minTotalMoves=0;
        
        for(int i=1;i<numsSize;++i)
        {
            minNum=minNum>nums[i]?nums[i]:minNum;
        }
        for(int i=0;i<numsSize;++i)
        {
            minTotalMoves+=nums[i]-minNum;
        }
        
        return minTotalMoves;
    }
    

Log in to reply
 

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