文章目录
- 1. 题目
- 2. 解题
1. 题目
样例 1
输入: [3, 4, 6, 6, 3]
输出: 7
说明: [3, 4, 6, 6, 3] -> [4, 5, 7, 6, 4] -> [5, 6, 7, 7, 5] -> [6, 7, 8, 7, 6] -> [7, 8, 8, 8, 7] -> [8, 9, 9, 8, 8] -> [9, 9, 10, 9, 9] -> [10, 10, 10, 10, 10]
来源:https://tianchi.aliyun.com/oj/164426199705086870/193936950952137404
2. 解题
- 找到最小的元素,每个元素跟其做差,求和
class Solution {
public:/*** @param arr: the array* @return: determine the number of moves to make all elements equals*/long long arrayGame(vector<int> &arr) {// write your code hereint ans = 0, m = *min_element(arr.begin(), arr.end());for(int i = 0; i < arr.size(); ++i)ans += arr[i]-m;return ans;}
};
50ms C++
我的CSDN博客地址 https://michael.blog.csdn.net/
长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!