Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

Increasing all elements by 1 except one element, equals to decreasing that one element.

class Solution {
public:
    int minMoves(vector<int>& nums) 
    {
        int minv = *min_element(nums.begin(), nums.end());
        
        int ret = 0;
        for(auto v : nums) ret += v - minv;
        
        return ret;
    }
};
posted on 2016-11-12 11:57  Tonix  阅读(88)  评论(0编辑  收藏  举报