517 Super Washing Machines 超级洗衣机
详见:https://leetcode.com/problems/super-washing-machines/description/
C++:
class Solution { public: int findMinMoves(vector<int>& machines) { int sum = accumulate(machines.begin(), machines.end(), 0); if (sum % machines.size() != 0) { return -1; } int res = 0, cnt = 0, avg = sum / machines.size(); for (int m : machines) { cnt += m - avg; res = max(res, max(abs(cnt), m - avg)); } return res; } };
参考:http://www.cnblogs.com/grandyang/p/6648557.html