We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 293d6d2 commit 0200775Copy full SHA for 0200775
scripts/algorithms/S/Super Washing Machines/Super Washing Machines.cpp
@@ -1,14 +1,15 @@
1
+// Runtime: 18 ms (Top 41.09%) | Memory: 13 MB (Top 43.64%)
2
class Solution {
3
public:
4
int findMinMoves(vector<int>& machines) {
- int total = accumulate(machines.begin(), machines.end(), 0);
5
+ int total = accumulate(machines.begin(), machines.end(), 0);
6
if (total % machines.size()) return -1; // impossible
7
- int avg = total / machines.size(), ans = 0, prefix = 0;
8
+ int avg = total / machines.size(), ans = 0, prefix = 0;
9
for (auto& x : machines) {
- ans = max({ans, abs(prefix), x - avg});
10
- prefix += x - avg;
+ ans = max({ans, abs(prefix), x - avg});
11
+ prefix += x - avg;
12
}
- return ans;
13
+ return ans;
14
-};
15
+};
0 commit comments