Skip to content

Commit 0200775

Browse files
committed
Runtime: 18 ms (Top 41.09%) | Memory: 13 MB (Top 43.64%)
1 parent 293d6d2 commit 0200775

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
// Runtime: 18 ms (Top 41.09%) | Memory: 13 MB (Top 43.64%)
12
class Solution {
23
public:
34
int findMinMoves(vector<int>& machines) {
4-
int total = accumulate(machines.begin(), machines.end(), 0);
5+
int total = accumulate(machines.begin(), machines.end(), 0);
56
if (total % machines.size()) return -1; // impossible
67

7-
int avg = total / machines.size(), ans = 0, prefix = 0;
8+
int avg = total / machines.size(), ans = 0, prefix = 0;
89
for (auto& x : machines) {
9-
ans = max({ans, abs(prefix), x - avg});
10-
prefix += x - avg;
10+
ans = max({ans, abs(prefix), x - avg});
11+
prefix += x - avg;
1112
}
12-
return ans;
13+
return ans;
1314
}
14-
};
15+
};

0 commit comments

Comments
 (0)