We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1752528 commit 3903ad4Copy full SHA for 3903ad4
scripts/algorithms/S/Super Washing Machines/Super Washing Machines.rs
@@ -0,0 +1,25 @@
1
+// Runtime: 0 ms (Top 100.0%) | Memory: 2.30 MB (Top 10.0%)
2
+
3
+impl Solution {
4
5
+ pub fn find_min_moves(machines: Vec<i32>) -> i32 {
6
+ let total: i32 = machines.iter().sum();
7
+ let machines_size = machines.len() as i32;
8
9
+ if total % machines_size != 0 {
10
+ return -1;
11
+ }
12
13
+ let avg = total / machines_size;
14
+ let mut cnt = 0;
15
+ let mut max_cnt = 0;
16
17
+ for i in 0..machines_size {
18
+ cnt += machines[i as usize] - avg;
19
+ max_cnt = max_cnt.max((cnt.abs()).max(machines[i as usize] - avg));
20
21
22
+ max_cnt
23
24
25
+}
0 commit comments