LeetCode 1089. Duplicate Zeros

Problem Statement


impl Solution {
pub fn duplicate_zeros(arr: &mut Vec<i32>) {
let n = arr.len();
let mut j = n;
for i in 0..n {
if arr[i] == 0 {
j += 1;
}
}

let mut i : i32 = (n - 1) as i32;
while i >= 0 {
j -= 1;
if j < n {
arr[j] = arr[i as usize];
}

if arr[i as usize] == 0 {
j-= 1;
if j < n {
arr[j] = 0;
}
}
i -= 1;
}
}
}