My Golang Solution


  • 0
    Y
    func minMoves(nums []int) int {
        sort.Ints(nums)
    
        count := 0
        lenNum := len(nums) - 1
    
        for i := 0 ; i < lenNum ; i++ {
            count += (nums[i+1] - nums[i]) * (lenNum - i)
            
        }
        
        return count
    }
    

Log in to reply
 

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