1089. Duplicate Zeros Easy

@problem@discussion
#Array#Two Pointers



1/**
2 * [1089] Duplicate Zeros
3 *
4 * Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.
5 * Note that elements beyond the length of the original array are not written. Do the above modifications to the input array in place and do not return anything.
6 *  
7 * Example 1:
8 * 
9 * Input: arr = [1,0,2,3,0,4,5,0]
10 * Output: [1,0,0,2,3,0,0,4]
11 * Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]
12 * 
13 * Example 2:
14 * 
15 * Input: arr = [1,2,3]
16 * Output: [1,2,3]
17 * Explanation: After calling your function, the input array is modified to: [1,2,3]
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	1 <= arr.length <= 10^4
23 * 	0 <= arr[i] <= 9
24 * 
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/duplicate-zeros/
29// discuss: https://leetcode.com/problems/duplicate-zeros/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34    pub fn duplicate_zeros(arr: &mut Vec<i32>) {
35        
36    }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_1089() {
47    }
48}
49


Back
© 2025 bowen.ge All Rights Reserved.