My solution.


  • 0
    O
    class Solution {
    public:
        int minMoves(vector<int>& nums) {
    
            if (nums.size() == 0 || nums.size() == 1)
                return 0;
            
            sort(nums.begin(), nums.end());
            
            int count = 0;
            for(int i = nums.size()-1; i > 0; i--)
            {
                count += nums.at(i) - nums.at(0);
            }     
            return count;
        }
    };
    

Log in to reply
 

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