Skip to content

Commit 3903ad4

Browse files
committed
Runtime: 0 ms (Top 100.0%) | Memory: 2.30 MB (Top 10.0%)
1 parent 1752528 commit 3903ad4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)