Minimum Moves to Equal Array Elements LeetCode solution in C++
1class Solution {2public:3int minMoves(vector<int> &nums) {4// sorting the array to get min at the first5sort(nums.begin(), nums.end());6int cnt = 0, n = nums.size();78// Now we have to make min equal to every number and keep adding the count9for (int i = 1; i < n; i++) cnt += nums[i] - nums[0];1011return cnt;12}13};